Interview Prep/Networking/Load balancers and reverse proxies

An ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.

IntermediateTroubleshootingLoad balancers and reverse proxies
Answer

Likely causes → The target closed an idle keep-alive connection at the same moment the ALB sent a new request on it. This happens when the backend's keep-alive timeout is shorter than the ALB idle timeout (60 s default), e.g. Node.js keepAliveTimeout 5 s, gunicorn --keep-alive 2.

Diagnose →

aws elbv2 describe-load-balancer-attributes --load-balancer-arn <arn> \
  --query "Attributes[?Key=='idle_timeout.timeout_seconds']"
# check access logs: target_processing_time = -1 and 502 on low-traffic periods

Fix → Make the backend keep-alive longer than the ALB's idle timeout:

server.keepAliveTimeout = 65000;
server.headersTimeout = 66000;

For nginx targets: keepalive_timeout 75s;.

Prevent → Rule of thumb: each inner hop's idle timeout must exceed the outer hop's.

All Networking questions Roadmap: Networking for DevOps

More on Load balancers and reverse proxies