The Sticky Session Pattern: When Statelessness Costs More Than It Saves

2026-06-04

The textbook rule is "make your servers stateless so any request can go to any node." It's good advice — until you're paying to rebuild expensive per-user state on every request. Sticky sessions (also called session affinity) route all requests from a given client to the same backend node, so that node can keep cached or in-memory state for that user.

The load balancer picks a node on the first request and "pins" subsequent requests to it, usually via a cookie (JSESSIONID, AWSALB) or a hash of the client IP. AWS ALB, NGINX (ip_hash or sticky cookie), and HAProxy all support this natively.

When stickiness earns its keep:

What it costs you:

Rule of thumb: if the cost of rebuilding per-user state on a cold node exceeds ~50ms and that state is requested more than once per minute per user, stickiness is probably worth it. Below that threshold, the cache-miss tax is cheaper than the operational complexity stickiness adds.

Hybrid approach that usually wins: use sticky sessions as a performance optimization, not a correctness requirement. Keep authoritative state in Redis or the database. Treat the in-memory copy as a cache that any node could rebuild. Now you get the latency win without the failover nightmare — losing a node degrades performance for affected users, but doesn't break them.

See it in action: Check out Session Vs JWT: The Differences You May Not Know! by ByteByteGo to see this theory applied.
Key Takeaway: Sticky sessions are a latency optimization, not a state management strategy — keep the source of truth elsewhere and treat node affinity as a cache hint that can be safely violated.

All newsletters