Why it matters
Wrong LB config causes connection failures, uneven distribution, or lost connections during deploys. Getting it right takes learning; the standard patterns work.
Advertisement
The architecture
L4 LB (TCP): NLB, HAProxy TCP mode. Doesn't parse HTTP; treats WebSocket as opaque TCP. Fast, simple.
L7 LB (HTTP): ALB, NGINX. Understands HTTP upgrade; can inspect headers. More features, slightly slower.
Advertisement
How it works end to end
Sticky methods: cookie-based (L7), IP hash (either), consistent hashing (custom).
Health checks: check WebSocket endpoint or dedicated /health. If backend unhealthy, LB stops sending new connections. Existing connections stay (or forcefully closed based on config).
Draining: on backend restart, LB stops new connections but existing continue. Client reconnects to healthy backend.