How do you tune ALB idle timeout and backend keep-alive to avoid 502s?
IntermediateProductionLoad Balancing, Proxies & nginx in Production
Answer
ALB closes idle connections after 60 seconds by default. If the backend closes first (nginx keepalive_timeout 75s is fine, Node default 5s is not), the ALB may send a request on a connection that the backend just closed and returns 502.
Set the backend keep-alive timeout above the ALB idle timeout: Node server.keepAliveTimeout = 65000, gunicorn --keep-alive 75, nginx keepalive_timeout 75s.
More on Load Balancing, Proxies & nginx in Production
How do you choose between ALB, NLB and an nginx or Envoy fleet?IntermediateWhich nginx directives matter most for a production reverse proxy?IntermediateHow do you do rate limiting and abuse protection in nginx?IntermediateHow do you achieve zero-downtime configuration reloads in nginx and HAProxy?IntermediateHow would you design a highly available load-balancing tier on-prem or in a colo?AdvancedHow do you perform a blue/green deployment at the load balancer level?Intermediate