Session Affinity and Its Problems
You'll learn what session affinity (sticky sessions) is, why load-balanced systems sometimes use it, and the scalability challenges it introduces.
What Is Session Affinity?
Session affinity, often called sticky sessions, is when a load balancer consistently routes all requests from the same user to the same backend server. Instead of distributing requests freely across your server pool, the load balancer "remembers" which server handled a user's first request and keeps sending that user back to the same server.
Think of it like always going to the same checkout clerk at a grocery store who remembers what bags you brought—convenient, but creates imbalance if everyone tries to use the same clerk.
Why It's Sometimes Needed
Session affinity exists because many applications store session state in memory on individual servers—user login details, shopping carts, or temporary data. If subsequent requests land on a different server, that state is lost unless you've designed for statelessness.
It's a band-aid solution for stateful applications in load-balanced environments.
The Problems It Creates
Uneven load distribution: Popular users or "heavy" sessions concentrate on specific servers, defeating the purpose of load balancing. One server might be overloaded while others sit idle.
Reduced fault tolerance: If a server crashes, all users "stuck" to it lose their sessions, even though healthy servers exist.
Scaling complications: You can't easily scale down (removing a server disrupts its sticky users) or add servers (existing users won't benefit).
No true horizontal scalability: Your system's capacity becomes limited by individual server capacity, not your total server pool.
The better solution? Design stateless applications or use shared session storage (databases, Redis) so any server can handle any request.
Key Takeaway:
Session affinity trades scalability and fault tolerance for convenience in stateful systems—it should be avoided when possible by designing for statelessness or using external session storage.