API Gateway throttling in AWS - Time & Space Complexity
When using API Gateway throttling, we want to understand how the number of requests affects the system's behavior.
Specifically, how does the throttling process handle increasing request volumes?
Analyze the time complexity of throttling requests in API Gateway.
// Pseudocode for API Gateway throttling
for each incoming request {
if (currentRequestCount < throttleLimit) {
allow request
increment currentRequestCount
} else {
reject request with 429 error
}
}
This sequence checks each request against a limit and either allows or rejects it.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Checking and updating the current request count for each incoming request.
- How many times: Once per request received by the API Gateway.
Each new request triggers one check and possibly an update. So, as requests increase, operations increase at the same rate.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 checks and updates |
| 100 | 100 checks and updates |
| 1000 | 1000 checks and updates |
Pattern observation: The number of operations grows directly with the number of requests.
Time Complexity: O(n)
This means the work done grows linearly as more requests come in.
[X] Wrong: "Throttling happens instantly without checking each request."
[OK] Correct: Each request must be checked against the limit, so the system does work proportional to the number of requests.
Understanding how throttling scales helps you design systems that handle traffic smoothly and avoid overload.
"What if the throttle limit was dynamic and changed based on time of day? How would the time complexity change?"
Practice
Solution
Step 1: Understand API Gateway throttling purpose
API Gateway throttling is designed to control the rate of incoming requests to prevent backend overload.Step 2: Evaluate options against throttling purpose
Only To limit the number of requests to protect backend services from overload correctly describes throttling as limiting requests to protect backend services.Final Answer:
To limit the number of requests to protect backend services from overload -> Option BQuick Check:
Throttling = Limit requests [OK]
- Confusing throttling with encryption
- Thinking throttling speeds up responses
- Assuming throttling stores logs
Solution
Step 1: Identify correct AWS API Gateway throttling syntax
The correct syntax uses camelCase keys like rateLimit and burstLimit with numeric values.Step 2: Compare options to AWS documentation style
rateLimit: 100, burstLimit: 200 matches the correct syntax format; others use invalid or pseudo-code styles.Final Answer:
rateLimit: 100, burstLimit: 200 -> Option CQuick Check:
Correct syntax uses camelCase keys [OK]
- Using underscores instead of camelCase
- Using function calls instead of key-value pairs
- Confusing method names with settings
rateLimit: 50 and burstLimit: 100, what happens when 120 requests arrive simultaneously?Solution
Step 1: Understand burstLimit and rateLimit roles
BurstLimit allows short spikes up to 100 requests at once; rateLimit controls steady rate at 50 requests per second.Step 2: Analyze 120 simultaneous requests
Up to 100 requests are allowed immediately (burst), the remaining 20 exceed burst and get throttled.Final Answer:
Up to 100 requests are processed immediately; the rest are throttled -> Option AQuick Check:
BurstLimit = immediate spike limit [OK]
- Confusing rateLimit with burstLimit
- Assuming all requests pass immediately
- Thinking requests queue without throttling
rateLimit: 200 and burstLimit: 300. However, clients report receiving HTTP 429 errors even when sending 150 requests per second. What is the most likely cause?Solution
Step 1: Understand causes of HTTP 429 in API Gateway
429 errors mean throttling triggered due to exceeding limits.Step 2: Check usage plan and API key limits
Usage plans or API keys can have lower throttling limits overriding global settings, causing 429 errors at lower rates.Final Answer:
The usage plan or API key limits are lower than throttling settings -> Option AQuick Check:
Usage plan limits override throttling [OK]
- Blaming backend service for 429 errors
- Assuming cache affects throttling
- Thinking high limits cause throttling
Solution
Step 1: Match throttling settings to traffic patterns
RateLimit controls steady request rate; BurstLimit allows short spikes above steady rate.Step 2: Apply to given traffic
Set rateLimit to steady 300 requests/sec and burstLimit to 1000 for short spikes.Final Answer:
Set rateLimit to 300 and burstLimit to 1000 -> Option DQuick Check:
RateLimit steady, BurstLimit spike [OK]
- Swapping rateLimit and burstLimit values
- Setting both limits too low
- Ignoring burstLimit for spikes
Ready to prove it?
Pass the test and this pattern moves unknown
