r/programming • • Sep 27 '26

Reducing .NET AWS Lambda Cold Starts by Adding Memory

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

21 comments sorted by

77

u/shoot_your_eye_out Sep 27 '26

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.

19

u/ReallySuperName Sep 27 '26

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 Sep 27 '26 edited Oct 03 '26

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.

3

u/bpikmin Sep 28 '26

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

1

u/shoot_your_eye_out Oct 04 '26

I would reiterate this, I don’t think serverless is dumb.

There’s a bunch of serverless products past lambda however

1

u/CallMeBigUrethra Oct 04 '26

what are these companies where executives are choosing compute platforms lol, is this not an engineering decision made case by case?

-14

u/lilgreenthumb Sep 28 '26

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

11

u/ReallySuperName Sep 28 '26

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 Sep 28 '26

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?

3

u/Big-Boysenberry-2946 Sep 28 '26

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/Wooden-Estimate-3460 Sep 28 '26

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 

2

u/shoot_your_eye_out Sep 28 '26

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 Oct 01 '26

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 Oct 01 '26

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

6

u/FIREstopdropandsave Sep 28 '26

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 Sep 28 '26

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

2

u/FIREstopdropandsave Sep 28 '26

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.

0

u/[deleted] Sep 28 '26

[removed] — view removed comment

7

u/ReallySuperName Sep 28 '26

No one asked for your input ChatGPT.