System Design
8. Load Balancing and ScalabilityAnimated
Sticky Sessions
Routing a user to the same server repeatedly.
The idea
The balancer uses a cookie or hash so a user keeps hitting the server that holds their session.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- client
- gateway / proxy
- service
- cache
- data store
- queue / stream
The balancer sets a cookie or hashes the client address.
- step:
- 1/4
- at:
- Client (cookie: A)
1/9
The green dot is a request moving through the system.
Step by step
- 1First request chooses a server
- 2The balancer sets a cookie
- 3Later requests follow the cookie
- 4If the server dies the session is lost
Where it is used
Legacy stateful apps.
Watch out for
Uneven load and lost sessions on failure.