Behind a load balancer, users get logged out randomly or lose their cart between clicks.
BeginnerTroubleshootingLoad balancers and reverse proxies
Answer
Likely causes → Sessions are stored in the memory of each app instance, and the LB spreads requests across instances. Each request may land on an instance that doesn't know the session.
Diagnose →
curl -s -c /tmp/c -b /tmp/c -I https://app.example.com/ | grep -i -E 'set-cookie|x-served-by'
# repeat a few times and see if the backend changes along with the session
Fix → Short term: enable stickiness (ALB stickiness.enabled=true with lb_cookie). Proper fix: move sessions to a shared store (Redis, database) or use stateless signed tokens, so any instance can serve any request.
Prevent → Design apps stateless from day one; stickiness hurts scale-in and uneven load.
More on Load balancers and reverse proxies
nginx returns `502 Bad Gateway` and the error log says `connect() failed (111: Connection refused) while connecting to upstream`.Beginnernginx returns `504 Gateway Time-out` with `upstream timed out (110: Connection timed out) while reading response header from upstream`.BeginnerAn ALB target group shows all targets `unhealthy` with `Health checks failed with these codes: [404]`.BeginnerAn ALB returns sporadic `502`s, and access logs show `elb_status_code=502` with `target_status_code=-`. Load is low.Intermediatenginx logs `upstream prematurely closed connection while reading response header from upstream`.Intermediatenginx error log shows `no live upstreams while connecting to upstream` and every request gets 502.Intermediate