What it is
Sticky routing sends every message from a client to the same node for the life of its session. When a node holds in memory state such as an open WebSocket or a partial buffer, any other node would not know how to handle the message.
How stickiness is achieved
- A consistent hash of the user id maps the client to a node.
- Or a routing token issued at connect time names the node to return to.
- The load balancer reads that key and pins the client.
The tradeoffs
- A pinned node becomes a hot spot if its clients are unusually active.
- When that node dies, its sessions are lost and must be rebuilt elsewhere.
- Scaling out does not rebalance existing sessions, only new ones.
Reducing the pain
- Keep node local state small and back it with a shared store so recovery is cheap.
- Use consistent hashing so adding a node moves only a fraction of sessions.
Key idea
Sticky routing pins a client to the node holding its session state, trading away easy rebalancing and node failure tolerance for the ability to keep state in memory.