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.

WebSocket LB optionsL4 LBopaque TCPL7 LBHTTP-awareSticky routingcookie / IP hashL4 for throughput; L7 for routing intelligence; both need sticky for reconnects
LB choices for WS.
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.