How it works
The explanation, with examples you can run.
Concurrency is the real limit
concurrency = requests per second x average duration (s) = 5,000 x 0.2 = 1,000By default an account has 1,000 concurrent executions per Region, shared by every function in it (it can be raised to tens of thousands on request). On top of that, each function can scale by at most 1,000 new environments every 10 seconds. Above either limit, synchronous calls get a 429 TooManyRequestsException, and asynchronous events are retried for a while before being dropped or sent to a failure destination.
The pool being shared is the surprise: a noisy batch function can throttle your checkout API. Two controls help:
- Reserved concurrency sets aside part of the pool for one function and caps it at that number. Setting it to 0 stops a function entirely, a useful emergency switch.
- Provisioned concurrency keeps a number of environments initialised and ready, removing cold starts for that much traffic. You pay for it while it is configured.
Cold starts
A cold start costs the time to create the environment, download the code and run your init code: from well under a second for a small Node.js or Python function to several seconds for a large Java app with heavy frameworks. To shrink it: keep packages small, do less work at import time, pick more memory (which also gives proportionally more CPU), and for Java, Python 3.12+ and .NET 8+, consider SnapStart, which restores environments from a snapshot taken after init. Code that runs outside the handler runs once per environment, so put SDK clients and connection setup there and reuse them.
How Lambda fails your other systems
- Connection storms: 1,000 environments each opening a database connection can exhaust a relational database. Use RDS Proxy, keep per-environment pools to one or two connections, or cap the function with reserved concurrency.
- Retries and duplicates: asynchronous invocations and event source mappings (SQS, Kinesis, DynamoDB Streams) retry on failure, and delivery is at least once. Handlers must be idempotent.
- Timeouts: the maximum is 15 minutes, and the default is only 3 seconds. Set it just above your real worst case, and below the visibility timeout of any SQS queue that triggers the function.
- Poison messages: with SQS, one bad message can block or retry forever. Configure partial batch responses and a dead-letter queue.
Lambda is excellent for spiky, event-driven work and glue between AWS services. For steady high throughput, long-running jobs or many open connections, containers are often cheaper and simpler.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.