Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

An ALB returns 502 intermittently during deployments. How do you stop that?

IntermediateScenarioEC2, Auto Scaling and Load Balancing
Answer

Situation read → Targets are being deregistered with in-flight requests, or the app closes keep-alive connections early.

What I'd do →

  1. Set deregistration delay to match the longest request, such as 30 to 60 seconds
  2. Make the app handle SIGTERM and finish requests
  3. Set app keep-alive timeout greater than the ALB idle timeout (60 s default)
  4. Use slow start for new targets
  5. Check HTTPCode_ELB_502_Count and target response time metrics

Why → A backend closing idle connections sooner than the ALB expects causes 502s on reused connections.

Interview tip → State the rule: backend keep-alive greater than load balancer idle timeout.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing