Lambda concurrency, cold starts and failures
Concurrency limits, reserved and provisioned capacity, SnapStart, retries, dead letters, partial batch failures and idempotency on Lambda.
Lambda concurrency, cold starts and failures
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Concurrency is requests per second times average duration. The default account limit is 1,000 per Region, shared by all functions.
- Reserved concurrency guarantees and caps one function. Provisioned concurrency keeps initialized environments ready and costs money while it does.
- Cold starts happen when a new environment is needed. Smaller packages, lighter init, SnapStart or provisioned concurrency reduce them.
- Who retries depends on the invocation type: the caller for synchronous, Lambda for asynchronous, the event source for queues and streams.
- Send events that keep failing to a destination or dead-letter queue, and report partial batch failures.
- Delivery is at least once, so make handlers idempotent.
Scaling is per request
Standard Lambda gives each in-flight request its own execution environment. So the number of environments you need is:
concurrency = requests per second x average duration in seconds
100 req/s x 0.1 s = 10
100 req/s x 1.0 s = 100
500 req/s x 0.2 s = 100
5000 req/s x 0.2 s = 1000
A slow dependency raises concurrency as surely as a traffic spike. The default limit is 1,000 concurrent executions per Region across all functions (new accounts can start lower), and you can ask for more. Requests per second are also capped at ten times that concurrency. Each function can add at most 1,000 environments every 10 seconds. Beyond any of these you are throttled.
Two concurrency controls
Reserved concurrency sets aside part of the account pool for one function and is also its ceiling. It protects a critical function from noisy neighbours, and protects a fragile database from a function. At least 100 must stay unreserved. Setting it to 0 switches a function off, which is a handy emergency brake.
Provisioned concurrency keeps environments initialized in advance. It costs money whether used or not, applies to a version or alias, and can follow a schedule or utilization. Think of reserved as reserving tables, and provisioned as paying staff to stand ready at them.
Cold starts
A cold start is the delay when a new environment must be created and initialized. It happens on first use, when scaling up, and after deployments. To reduce it:
- ship less code and import only what you use;
- give more memory, which speeds init too;
- defer setup that some requests never need;
- use SnapStart (Java 11+, Python 3.12+, .NET 8+ managed runtimes, and container images with hooks), which restores from a snapshot of an initialized environment. Anything that must be unique or fresh, such as random seeds, connections and credentials, needs attention after restore. It can’t be combined with provisioned concurrency, and outside Java it carries extra charges;
- use provisioned concurrency for strict latency.
Measure the Init Duration in your logs before optimizing. It may affect a tiny fraction of requests.
Who retries
| Invocation | On error |
|---|---|
| Synchronous | Lambda returns the error; the caller decides |
| Asynchronous | Lambda retries twice more by default |
| SQS | messages return after the visibility timeout |
| Kinesis, DynamoDB streams | the batch is retried and blocks its shard |
For asynchronous calls, throttles and system errors are retried with backoff for up to 6 hours. When attempts are exhausted or the event is too old, it’s dropped unless you configured an on-failure destination (it records why it failed) or a dead-letter queue. Configure one.
For SQS, set the queue’s visibility timeout to at least six times the function timeout and give it a dead-letter queue. For streams, set maximum retries and record age, consider splitting failing batches, and send failures somewhere you’ll look.
Partial failure and duplicates
One failure in a batch normally fails all of it. With ReportBatchItemFailures you return just the failed IDs:
def handler(event, context):
failed = []
for record in event["Records"]:
try:
charge(json.loads(record["body"]))
except Exception:
failed.append({"itemIdentifier": record["messageId"]})
return {"batchItemFailures": failed}
I fed it three orders, one with a negative total, twice. It charged two orders on the first delivery and none on the second, returning only the bad message both times.
The second pass is the important one. Event sources deliver at least once, so charge must be idempotent. My stand-in remembered IDs in a set, which is useless across environments. In production, use a conditional write to DynamoDB or the Powertools idempotency utility.
Beware loops: a function writing to the bucket or queue that triggers it. Lambda detects some of these and stops them, not all. Alarm on errors, throttles, duration, iterator age and dead-letter depth.
Test the failure path on purpose. Throw from the handler, then check that the event lands where you expect and that someone is told.
About the video
The embed is James Eastham’s 13-minute “AWS Lambda Concurrency Explained” from January 2023. Its chapters benchmark a function, enable provisioned concurrency, improve the code and demonstrate reserved concurrency. It covers concurrency and cold starts only, not retries or failures, which the linked talk by Yan Cui does. It also predates current SnapStart runtimes and scaling rates. I judged it from chapters and description; its audio is flagged as original US English.
What was run: the batch handler and arithmetic ran in local Python, not Lambda. Limits and retry behaviour come from the Lambda developer guide, checked in November 2026.
Check yourself
A function takes 200 ms and receives 5,000 requests per second. What concurrency does it need?
1,000, which is the whole default account limit, so every other function in the Region would be starved without a quota increase or reservations.
An asynchronous function throws on every attempt and no destination is configured. What happens to the event?
Lambda tries it three times in total and then discards it.
One bad message in a batch of ten makes all ten reappear in SQS again and again. What do you change?
Enable ReportBatchItemFailures and return only the failed message IDs, and give the queue a dead-letter queue so the bad one is eventually set aside.
Why might setting reserved concurrency to 5 protect a database?
It caps the function at five environments, and so at about five concurrent connections, however much traffic arrives.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.