What is a sticky session

LearnNewTech
2 min readApr 27, 2022

Session stickiness, a.k.a., session persistence, is a process in which a load Balancer creates an affinity between a client and a specific network server for the duration of a session, (i.e., the time a specific IP spends on a website). Using sticky sessions can help improve user experience and optimize network resource usage.

With sticky sessions, a load balancer assigns an identifying attribute to a user, typically by issuing a cookie or by tracking their IP details. Then, according to the tracking ID, a load balancer can start routing all of the requests of this user to a specific server or instance for the duration of the session.

This can prove very helpful, as HTTP/S is a stateless protocol that was not devised with session persistence in mind. Nevertheless, many web applications do have the need to serve personalized user data (e.g., keep logs of items in a shopping cart or chat conversations) over the course of a session.

Without session persistence, the web application would have to maintain this information across multiple servers, which can prove inefficient — especially for large networks.

Session stickiness: Advantages and disadvantages

Session stickiness offers a number of benefits that can improve your web application’s performance, including:

  • Minimized data exchange — When using sticky sessions, servers within your network don’t need to exchange session data, a costly process when done on scale.
  • RAM cache utilization — Sticky sessions allow for more effective utilization of your application’s RAM cache, resulting in better responsiveness.

That said, sticky sessions also make it more difficult to keep servers in balance. A server can become overloaded if it accumulates too many sessions, or if specific sticky sessions require a high number of resources. This could result in your load balancer having to shift a client to a different server mid-session, resulting in data loss.

--

--