
1,000 Requests Hit Your API at Once. Can API Gateway and Lambda Handle It?
What happens when 1,000 requests hit your API at the same time? Why do some requests return 429 errors, and why does Lambda experience throttling? In this practical guide, you'll learn how Amazon API Gateway throttling, Lambda concurrency, reserved concurrency, and exponential backoff work together. Understand the request flow, identify bottlenecks, and learn practical ways to prepare your serverless API for increasing traffic.
Introduction
Your API works perfectly during development.
You test it with a few requests, everything looks good, and you deploy it.
But then something changes.
More users start accessing your application at the same time.
Some requests take longer. Others return
429 Too Many Requests . Your Lambda function starts experiencing throttling.What changed?
Your code might be perfectly fine. The problem could be how your API handles incoming traffic and how many requests your Lambda function can process simultaneously.
In this article, we'll understand how Amazon API Gateway and AWS Lambda handle increasing traffic, why throttling happens, and how to configure these services to handle traffic more effectively.
1. Understand the Request Flow
Let's start with a simple serverless API architecture:
User | v API Gateway | v AWS Lambda | v API ResponseWhen a user sends a request:
- API Gateway receives the request.
- API Gateway checks its configured throttling limits.
- If the request is accepted, API Gateway invokes Lambda.
- Lambda executes your application logic.
- Lambda returns the result.
- API Gateway sends the response to the user.
This works well with normal traffic.
But what happens when hundreds or thousands of requests arrive within a short period?
That's where API Gateway throttling and Lambda concurrency become important.
2. What Happens When API Gateway Receives Too Many Requests?
Amazon API Gateway uses a token bucket mechanism to control incoming traffic.
There are two important settings:
Rate limit
The average number of requests allowed per second.
Burst limit
The number of requests that can be temporarily accommodated during a traffic spike.
For example, imagine you configure:
- Rate limit: 50 requests per second
- Burst limit: 100 requests
This allows an average request rate of 50 requests per second while accommodating short bursts within the configured burst capacity.
If incoming traffic exceeds the applicable throttling limits, API Gateway can return:
HTTP/1.1 429 Too Many RequestsThis means API Gateway is throttling requests because the configured capacity has been exceeded.
One important detail: API Gateway throttling limits are best-effort targets, not guaranteed hard limits.
3. What Is Lambda Concurrency?
Now let's understand what happens after API Gateway invokes Lambda.
Concurrency means the number of Lambda function executions running at the same time.
Imagine 100 requests reach your Lambda function, and all their executions overlap.
Your function may need 100 concurrent executions to handle them.
A useful way to estimate concurrency is:
Concurrency = Requests per second × Average durationLet's understand this with an example.
Suppose:
- Incoming requests: 100 per second
- Average Lambda execution duration: 0.5 seconds
Calculation:
100 × 0.5 = 50Your Lambda function needs approximately 50 concurrent executions to handle this traffic under these assumptions.
Now imagine your function takes 2 seconds instead of 0.5 seconds.
100 × 2 = 200Your function now needs approximately 200 concurrent executions.
This shows why execution duration matters.
Even if incoming traffic remains the same, slower Lambda executions can increase concurrency requirements.
4. Understand Lambda Reserved Concurrency
AWS Lambda provides a setting called Reserved Concurrency.
It allows you to reserve concurrency for a specific function and also sets the maximum number of concurrent executions that function can use.
For example:
Imagine your Lambda function has reserved concurrency set to 50.
This means:
- Up to 50 executions can run concurrently.
- Your function cannot scale beyond those 50 executions.
- Additional invocations can be throttled when the limit is reached.
Reserved concurrency is useful when you want to prevent one Lambda function from consuming all available account concurrency.
However, setting it too low can also restrict your API's ability to handle incoming traffic.
You can configure it through:
AWS Console → Lambda → Your Function → Configuration → Concurrency.
5. Why Are You Getting 429 Errors?
A
429 Too Many Requests response can happen at the API Gateway level when its throttling limits are exceeded.Lambda can also experience throttling when the available concurrency is insufficient.
These are two different situations.
API Gateway throttling
API Gateway rejects requests because the configured request rate or burst capacity has been exceeded.
Lambda throttling
Lambda cannot accept additional concurrent executions because the available concurrency limit has been reached.
Understanding where throttling happens is important because increasing API Gateway limits alone will not solve a Lambda concurrency problem.
You need to investigate both services.
6. How Should Your Application Handle 429 Errors?
Your application should not immediately retry every failed request.
Imagine 1,000 users receive throttling responses.
If all clients retry immediately, they can create even more traffic.
A better approach is Exponential Backoff.
Instead of retrying immediately, wait progressively longer before trying again.
For example:
First retry: 1 secondSecond retry: 2 secondsThird retry: 4 secondsYou should also add random jitter to avoid many clients retrying at exactly the same time.
For operations such as payments or order creation, make sure retries cannot cause duplicate operations. Use idempotency where appropriate.
7. How Can You Prepare Your API for Traffic Spikes?
Before deploying your API to production, consider these practical steps:
1. Configure API Gateway throttling
Choose appropriate rate and burst limits based on your application's expected traffic.
2. Understand Lambda concurrency
Estimate the concurrency required using your expected request rate and average execution duration.
3. Configure Reserved Concurrency carefully
Reserve enough capacity for important functions without unnecessarily restricting their scaling.
4. Optimize Lambda execution duration
Avoid unnecessary processing and investigate slow operations within your function.
5. Handle throttling responses
Make sure your clients handle
429 responses using appropriate retry strategies.6. Test under realistic traffic
Don't rely only on a few successful requests during development. Test how your API behaves when multiple requests arrive at the same time.
8. Final Thoughts
An API working correctly with 10 users doesn't automatically mean it will behave the same way with 1,000 users.
As backend developers, we need to think beyond writing code that returns a successful response.
We also need to understand incoming traffic, API throttling, Lambda concurrency, and execution duration.
Amazon API Gateway and AWS Lambda provide the building blocks for serverless APIs, but configuring them properly is an important part of building reliable applications.
Let's discuss:
If 1,000 requests hit your API at the same time, what would you investigate first?
API Gateway throttling, Lambda concurrency, or Lambda execution duration?
I'd be interested to hear how other developers approach this problem.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article