Cianplan

Level 1: Foundations · L1.3 Load balancing, reverse proxies, API gateways

Sticky sessions and stateless services

Explain why stickiness hurts balancing and how to move state out.

10 min · Free

What you take away

  • Affinity overrides the balancing algorithm: once a user is pinned, load is distributed by who arrived when, not by who is busy.
  • A newly scaled-out instance only receives new sessions, so it stays cold while the existing ones stay hot.
  • Connection draining finishes in-flight requests; it cannot move a session that lives in one process's memory.
  • Affinity is acceptable for warm caches and live connections — never for correctness.

How the class is laid out

  1. The problem
  2. The simple version
  3. What stickiness does to the pool
  4. When affinity is fine, and what replaces it
  5. Algorithms
  6. Health and draining
  7. L4 vs L7
  8. Proxy, gateway, mesh
  9. Stickiness
  10. Check your understanding