← Lessons

quiz vs the machine

Silver1050

System Design

Sticky Sessions

Pinning a user to one server, and why stateless beats it.

4 min read · intro · beat Silver to climb

What stickiness means

Sticky sessions, also called session affinity, tell a load balancer to keep routing the same client to the same backend server. The balancer remembers the mapping, often by setting a cookie or hashing the client address, so every follow up request lands on the host that holds that user state.

Why anyone uses it

  • A server may keep in memory session state like a shopping cart or login.
  • Reusing the same host can warm local caches for that user.

The downsides

  • If that server dies, its users lose their session state.
  • Load can become uneven because some sticky users are heavier than others.
  • Scaling and deploys are harder because you cannot freely move users.

The better default

The modern preference is stateless servers that store session data in a shared store such as a cache or database. Then any server can handle any request, the load balancer can route freely, and a dead host costs nobody their session.

Key idea

Sticky sessions pin a user to one server for local state, but stateless servers backed by a shared store scale and fail over more cleanly.

Check yourself

Answer to earn rating on the learn ladder.

1. What do sticky sessions do?

2. Why are stateless servers usually preferred?