API Gateway plus Lambda is throwing 429 and 502 errors under load. What's happening?
IntermediateScenarioScaling and performance
Answer
Situation read → 429s are throttling (API Gateway or Lambda concurrency); 502s are usually Lambda errors or timeouts surfacing through the gateway.
What I'd do →
- Check Lambda
Throttles,ConcurrentExecutions,ErrorsandDurationin CloudWatch. - If concurrency is maxed: the account limit (1,000 default per region) is shared by all functions. Request an increase, and set reserved concurrency so one function can't starve others.
- Check API Gateway stage and usage-plan throttling limits.
- For 502s: look for timeouts and malformed responses in Lambda logs (a proxy integration must return
statusCodeandbody). - Reduce duration: cold starts (provisioned concurrency), slow downstream calls, and DB connection storms (use RDS Proxy).
Why → Lambda concurrency is roughly RPS × duration; halving duration halves the concurrency you need.
Interview tip → Quote the formula concurrency = requests per second × average duration.
More on Scaling and performance
Traffic is expected to 10x for a sale next week. How do you prepare the platform?IntermediateThe HPA is configured but pods don't scale even though the app is slow. Why?BeginnerPods are Pending during a traffic spike because the cluster is out of capacity. What do you do now and long term?IntermediateThe database CPU is at 95% and the API is timing out. What's your approach?Intermediate"Too many connections" errors from Postgres after scaling the app out. How do you fix it?IntermediateLatency is fine on average but p99 is terrible. Where do you look?Advanced