Lambda concurrency and throttling in AWS - Time & Space Complexity
When many requests trigger a Lambda function, AWS controls how many run at once. We want to understand how the number of requests affects how often Lambda runs or gets slowed down.
How does Lambda handle many calls and when does it start delaying or rejecting them?
Analyze the time complexity of Lambda invocations with concurrency limits.
// Assume Lambda concurrency limit is set to 100
for (let i = 0; i < n; i++) {
lambda.invoke({ FunctionName: 'MyFunction', Payload: '{}' }, (err, data) => {
// handle response
});
}
This code triggers the Lambda function n times quickly, testing how concurrency limits affect execution.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Lambda function invocation API call
- How many times: n times, once per loop iteration
- Dominant operation: Each invocation request triggers Lambda execution or throttling
As the number of requests n grows, Lambda tries to run them all but can only run up to the concurrency limit at once.
| Input Size (n) | Approx. Lambda Invocations Started |
|---|---|
| 10 | 10 (all run immediately) |
| 100 | 100 (all run immediately, at concurrency limit) |
| 1000 | 100 run immediately, 900 throttled or delayed |
Pattern observation: Lambda runs up to the concurrency limit immediately; extra requests wait or get throttled.
Time Complexity: O(n)
This means the number of invocation requests grows directly with n, but actual running functions at once are capped.
[X] Wrong: "Lambda runs all requests instantly no matter how many."
[OK] Correct: Lambda limits how many run at once; extra requests get delayed or rejected to keep system stable.
Understanding how Lambda handles many requests helps you design systems that stay smooth and reliable under load. This skill shows you can think about real cloud limits and user experience.
"What if we increased the concurrency limit? How would the time complexity and throttling behavior change?"