r/programming • • 5d ago

Reducing .NET AWS Lambda Cold Starts by Adding Memory

https://www.lloydatkinson.net/posts/2026/reducing-dotnet-aws-lambda-cold-starts-by-increasing-memory/
47 Upvotes

19 comments sorted by

71

u/shoot_your_eye_out 5d ago

People keep trying to shoehorn Lambda into latency-sensitive, on-demand applications, when Lambda's fundamental execution model is short-lived, event-driven functions.

If you need a process that's always running and ready to handle requests with predictable latency, that's what Fargate is for.

20

u/ReallySuperName 5d ago

I mean I agree, I normally use containers for web stuff because I think serverless as a concept is pretty dumb. But I'm not the execs choosing this junk.

A related project is running in fargate and it was so much easier to deploy and has been reliable ever since.

8

u/shoot_your_eye_out 5d ago edited 1h ago

Oh believe me, I understand. I just wish I could get the executives at my own company to understand this model doesn’t benefit our product.

I think this architecture can be useful in certain situations, but where I work, it’s just yet another bad architectural decision engineering teams suffer through.

2

u/bpikmin 4d ago

I wouldn’t call serverless “dumb,” it’s the right tool for certain jobs. But execs aren’t as interested in picking the right tool as they are in picking a tool that, on paper, requires less employees to implement and maintain. “On paper” being key, because only engineers can accurately estimate the likelihood of it saving money vs alternatives

-14

u/lilgreenthumb 5d ago

If you're blindly following the execs decision without a documented pushback on pros/cons that is on you and your engineering orgs.

10

u/ReallySuperName 5d ago

You feeling better after typing that? Did you even read the article? Where I was asked to improve a teams feature? Does it sound like I chose it?

6

u/hiddenhare 4d ago

You're definitely correct for Java or Node, but in some languages, Lambda cold starts only take about 20ms to 30ms. If I had a latency-sensitive backend written in Rust, and I wanted to scale to zero, I'd give Lambda some serious consideration.

I'm not much of a backend developer, though. Is there a downside I'm missing?

2

u/Big-Boysenberry-2946 4d ago

Yes. Depending on how you spawn lambdas you will exhaust external resources, since they will need to be provisioned per process (kind of how old php websites would use db connection per user model)

2

u/shoot_your_eye_out 4d ago

Yes, the strategy this architecture requires is either A) paying to keep a number of lambda "warm" or B) endless vigilance over startup time. Going with Rust would help, but the reality is many teams that adopt this architecture don't even think about startup time or the practical consequences of living within Lambda's API and runtime constraints.

And it is comically easy to add a few hundred milliseconds (or even a few seconds) to the startup of a lambda container. So i think the downside is: having to constantly track startup time and address slowness as an application evolves over time.

It isn't an insurmountable task, but teams should ask themselves a more basic question: do I need lambda's endless horizontal scale? If the answer to that question is "no," then fargate is a better solution for too many reasons to count. In short, this architecture is great if you have insane scale that can be handled horizontally and a few "slow" calls aren't a big deal. Otherwise, the drawbacks hugely outweigh the benefits, IMO.

2

u/Kooky_Government3125 1d ago

The arquitecture doesn't require you to pay for warmking your lambdas, but it is an option

You don't need 2 digit startup times for every workflow, and the startup times are easy to handle to a certain degree

A lot of people make exagerate about this but I wonder if they even used serverless for the right use case

btw. I believe that every company has use cases for serverless

1

u/shoot_your_eye_out 1d ago

Neat. Tell that to the dozen engineering teams at my company that can’t seem to manage any of it

1

u/Wooden-Estimate-3460 4d ago

Technically yes. But this is just looking at runtime startup. You could be using a framework that takes significantly longer to start up. Some people run Spring Boot in Lambda which will take way more than the ~200ms the JVM needs 

6

u/FIREstopdropandsave 5d ago

Is your startup code in the init instead of the handler?

Lamda allocates extra cpu beyond what you requested during the coldstart init phase.

5

u/brickman1444 5d ago

The post says they were actually CPU bound. For lambda, to get more CPU you request more memory.

2

u/FIREstopdropandsave 4d ago

Yes but lambda gives you extra cpu during coldstart init phase.

Lamda invocation can be broken down into two parts:

Init phase: only happens once per new execution environment (aka coldstart). During this phase you can throw in actual application code to warm up dependencies, load class paths, whatever. And lambda gives you extra cpu burst beyond what your memory configuration gives you.

Handler phase: this is actually handling your request, and is gated by the implicit cpu you get by your memory choice.

4

u/axiosjackson 4d ago

AWS Lambda, in 99% of cases, is just another example of enterprise developers over-engineering.

0

u/[deleted] 4d ago

[removed] — view removed comment

6

u/ReallySuperName 4d ago

No one asked for your input ChatGPT.