EMZETT.
Login

Sticky sessions

In short: With sticky sessions, a load balancer always forwards a user’s requests to the same server so that session data stored there is found again.

In more detail: If a server keeps the session in its own memory, other servers would know nothing about it. The load balancer therefore remembers the assignment, usually via a cookie or the IP address.

In Depth

  • Disadvantage: If the server fails, the session is gone. Load is distributed unevenly.
  • Better: Keep sessions in shared storage (Redis, database) or in a signed token (for example JWT) held by the user. Then any server can handle any request (“stateless”).
  • Scaling: Stateless servers can be added and removed freely.
  • Exception: WebSockets stay tied to one connection anyway.

See also: Load balancing