A service makes many outbound calls and you're seeing intermittent connection timeouts through the NAT gateway. What's the cause?
AdvancedScenarioScaling and performance
Answer
Situation read → A NAT gateway supports up to 55,000 simultaneous connections to a single destination IP and port. High fan-out to one endpoint exhausts source ports.
What I'd do →
- Check the NAT gateway metric
ErrorPortAllocationandConnectionAttemptCountversusConnectionEstablishedCountin CloudWatch. - Fix in the app: reuse connections with keep-alive and pooling instead of a new TCP connection per call.
- If the destination is AWS (S3, DynamoDB, ECR), use VPC endpoints so traffic skips the NAT entirely; this also cuts cost.
- Spread load across more NAT gateways (one per AZ) or add secondary IPs to the NAT gateway for more ports.
- Check
TIME_WAITbuildup on the pods:ss -s.
Why → Port exhaustion looks like random timeouts and is invisible in app metrics.
Interview tip → ErrorPortAllocation is the exact metric name; use it.
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