Comparison
Layer 4 load balancingvsSession affinity
Layer 4 load balancing
the balancer picks a backend per TCP connection and never looks inside, so it cannot route on a path or retry a request.
Distributing traffic by connection at the transport layer, without parsing what is being carried. It is fast, protocol-agnostic and cheap, and it is blind: no path-based routing, no header inspection, no per-request retry, and no rebalancing of a connection once established. That last property is why one long-lived multiplexed connection sends every request to a single backend regardless of load.
Full entry →Session affinity
you pin each user to the same instance so the state cached in that process is still there on their next request.
Routing a client's requests consistently to one backend. It makes in-process state usable, which is sometimes the only practical option for WebSockets or large session data. It also breaks even load distribution, prevents clean draining on deploy, and turns one instance's death into a visible failure for a subset of users.
Full entry →