Hey, I’m a huge serverless user, I’ve built several applications on top of Lambda, Dynamo, S3, EFS, SQS, etc.
But I have never understood why would someone use Provisioned Concurrency, do you know a real use case for this feature?
I mean, if your application is suffering due to cold starts, you can just use the old-school EventBridge ping option and it costs 0, or if you have a critical latency requirement you can just go to Fargate instead of paying for provisioned concurrency, am I wrong?
I think you are right , we don’t use it as well and use the same techniques you already described against cold starts. Provisioned concurrency doesn’t even scale with your traffic so you are always over or under provisioned afaik.
pings won’t save you from cold starts. if the workload just crosses what the current capacity can handle, a new instance will be warmed up. you have no control over whether it will be a ping or an actual user. pinging works as long as one single instance can serve all demands.
fargate requires 24/7 running tasks, because the startup times are even worse than lambda’s. if you want 24/7 running tasks together with scaling and all, sure, do that, but it requires a whole lot more setup.
IMHO Provisioned Capacity and ping technique is to cover for poorly written Lambdas, Lambdas in languages that shouldn’t be used for Lambdas and use cases that shouldn’t be Lambdas.
However, the new Snapstart feature has the potential to make inappropriate languages the best choice languages. Runtime performance will be more important than cold start performance.
We have a Python FastAPI API behind Lambda and when it’s warm the response time is 100-200ms which is great. We just don’t want to suffer some cold invocations that take ~2s
From my empirical experience sometimes even using the ping option at 1-minute rate somehow a cold start could happen, it cuts down the cold start probability close to 0 but not 0.
Also, maybe you had more concurrent requests than warmed Lambdas so a good test would be to keep warm more instances
The broader serverless community provides open source libraries to “warm” Lambda functions via a pinging mechanism. This approach uses EventBridge rules to schedule invocations of the function every minute to help keep the execution environment active. As a result, this can increase the likelihood of using a warm environment when you invoke the function.
However, this is not a guaranteed way to reduce cold starts. It does not help in production environments when functions scale up to meet traffic. It also does not work if the Lambda service runs your function in another Availability Zone as part of normal load-balancing operations. Additionally, the Lambda service reaps execution environments regularly to keep these fresh, so it’s possible to invoke a function in between pings. In all of these cases, you experience cold starts despite using a warming library. This approach might be adequate for development and test environments, or low-traffic or low-priority workloads.
Additionally, you cannot target a warm environment for an invocation. The Lambda service determines which execution environment receives a request based upon internal queueing and optimization factors. This is no affinity for repeat requests or any concept of “sticky sessions”, as may be set on traditional load balancers.
I mean, if your application is suffering due to cold starts, you can just use the old-school EventBridge ping option and it costs 0
This isn’t nearly as effective as there’s no real way to make EventBridge keep 100 or 1000 or more environments warm. If you have a very low traffic application maybe this method still makes sense, but for anything else PC is going to be more reliable
I use it a lot in python or node, but the occasional 1-5s delay due to cold start is not what I would call a problem. Especially considering the overall cost benefit compared to running on dedicated compute. Even if Lambda doesn’t add a cold start delay, the Internet has inherently nondeterministic performance. I generally try to add delays into API calls during development to make it obvious where we need to compensate for potential delays with UI tricks. Delays happen regardless of your efforts and we should design for it.
We have hundreds of functions and use concurrency on dozens of functions. SnapStart has changed the rationale and we’ve moved several functions to that but provisioned concurrency is still very useful.
As others have said pinging a function can help keep it warm but aren’t a guarantee. When you get to a larger scale with lots of continuous parallel invocations, like consuming a Kinesis Stream or DynamoDB stream, the cold start latency is one of the major factors.
However there are other factors, specifically the fact you can auto scale and provisioned concurrency is cheaper if you utilize it fully. This can be tuned with the auto scaling.
While SnapStart has a lot of the same benefits outside of cost, the benefit provisioned concurrency is the startup logic can run entirely outside of the handler before an invocation. If you have code to load data at runtime into the function or initialize an expensive object this can make a significant difference that pinging just won’t have the same guarantees as provisioned concurrency.
Provisioned concurrency will still end up with cold starts unless you just way over provision which is what makes SnapStart more attractive as it can pull down the worst case cold start more.
I have a use case where we’re using API gateway with a cross-account Lambda as the API backend. API gateway has a hard max timeout of 29 seconds in this scenario and we expect daily spikes in traffic but most often none.
Our actual API logic is to update some stateful resources and currently it takes on average 20 seconds with a warm instance but often hits timeouts and gets retries from the client. If an instance has to cold start it will almost always time out with API gateway
Some of our callers will only call 2 or 3 times at once, others will call 100+. We keep a provisioned capacity on the backing Lambda of ~10 with an application auto scaling policy so that it can dial up and down to meet demands
I kind of wish you could define a concurrency boost % instead of defining the actual instance counts, like always leave 5% more containers running than my current workload is requiring…. Making it spawn a few more instances beyond what is needed and getting that cold start out of the way before traffic hits it