Interview Prep/Networking/Load Balancing, Proxies & nginx in Production

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.

All Networking questions Roadmap: Networking for DevOps

More on Load Balancing, Proxies & nginx in Production