Session persistence
medium 25 minSession persistence, also called sticky sessions or affinity, makes a load balancer send the same client to the same server.
Where it shows up
The same pattern appears across everyday software.
AWS Application Load Balancer
Offers duration-based and application-based cookies. If the target becomes unhealthy, the balancer picks a healthy one and the session sticks to that.
WebSockets on the same balancer
Its documentation calls WebSocket connections inherently sticky: the target that accepts the upgrade keeps the connection.
NGINX ip_hash
Uses the first three octets of an IPv4 address, or the whole IPv6 address, as the key. Neighbours in one IPv4 network therefore share a server.
HAProxy
Can insert a cookie that names the server, or choose by hashing the source address with balance source.
Kubernetes Services
Setting sessionAffinity to ClientIP keeps a client address on one Pod. The default time limit is 10,800 seconds, which is 3 hours.
The Twelve-Factor App
This widely read guide says sticky sessions should never be relied upon, and suggests a store with expiry, such as Memcached or Redis.