Interview Prep/Real-World Interview/Scaling and performance

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 →

  1. Check the NAT gateway metric ErrorPortAllocation and ConnectionAttemptCount versus ConnectionEstablishedCount in CloudWatch.
  2. Fix in the app: reuse connections with keep-alive and pooling instead of a new TCP connection per call.
  3. If the destination is AWS (S3, DynamoDB, ECR), use VPC endpoints so traffic skips the NAT entirely; this also cuts cost.
  4. Spread load across more NAT gateways (one per AZ) or add secondary IPs to the NAT gateway for more ports.
  5. Check TIME_WAIT buildup 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.

All Real-World Interview questions Roadmap: Interview readiness

More on Scaling and performance