AWS Lambda Concurrency and Throttling
- Lambda Concurrency Basics:
- Lambda functions can scale automatically and rapidly.
- Low-scale invocations result in fewer concurrent executions, while high-scale events can lead to up to 1000 concurrent Lambda executions.
- Reserved Concurrency:
- You can limit the number of concurrent executions by setting a reserved concurrency at the function level.
- Example: Setting a reserved concurrency of 50 means that the Lambda function can only have up to 50 concurrent executions.
- Invocations exceeding this limit will be throttled.
- Throttling Behavior:
- Synchronous invocations: Throttling results in a 429 error.
- Asynchronous invocations: Automatically retried and may go to a Dead Letter Queue (DLQ) if retries fail.
- Increasing Concurrency Limits:
- To have more than 1000 concurrent executions, you must open a support ticket with AWS to request higher limits.
- Concurrency Limit Implications:
- The concurrency limit applies to all functions in your AWS account.
- If one function exhausts the concurrency limit, other functions may be throttled.
- Example Scenario: A promotion causes one Lambda function to use all available concurrency, leading to throttling of other functions.
- Asynchronous Invocations and Throttling:
- If Lambda reaches its concurrency limit, additional asynchronous requests are throttled.
- Throttled events are retried for up to six hours, with retry intervals increasing exponentially from one second to a maximum of five minutes.
Cold Starts and Provisioned Concurrency
- Cold Starts:
- Occurs when a new Lambda instance is created, and code initialization takes place.
- Can result in higher latency for the first request, potentially impacting user experience.
- Provisioned Concurrency:
- Allocates concurrency in advance to avoid cold starts.
- Ensures lower latency for all invocations.
- Can be managed with Application Auto Scaling for scheduling or maintaining target utilization.
- Improvements in VPC:
- AWS has made improvements to reduce cold starts within a VPC, as detailed in a blog post from October/November 2019.
Additional Resources
- Diagrams and further explanations are available in the provided links for reserved concurrency and provisioned concurrency.
- It is recommended to review these diagrams in your own time for a better understanding.
Hands-On Practice
- The next step in the training involves practical exercises to see how concurrency works in AWS Lambda.