Sticky Session
Sticky sessions ensure that requests from a client always get routed to the same server before a session elapses.
Here is an example that describes what sticky sessions. Assume that you have logged in to a server. After a while, you send another request. If sticky sessions are not enabled, the request may be routed to another server, and you will be asked to log in again. If sticky sessions are enabled, all your requests are processed by the same server, and you do not need to repeatedly log in.
Sticky Sessions at Layer 4
Sticky sessions at Layer 4 use source IP addresses to maintain sessions. Requests from the same IP address are routed to the same backend server during the session.
Sticky sessions at Layer 4 will be invalid in the following scenarios:
- Source IP addresses of the clients change.
- Requests from the clients exceed the session stickiness duration.
- You can set the stickiness duration only if you select Weighted round robin as the load balancing algorithm.
- The default stickiness duration is 20 minutes, and the maximum duration is 60 minutes (that is, 1 hour).
Sticky Sessions at Layer 7
Sticky sessions at Layer 7 allow you to use load balancer cookies or application cookies to maintain sessions. Choose an appropriate sticky session type to better distribute requests across backend servers.
- Load balancer cookie: The load balancer generates a cookie after receiving a request from the client. All subsequent requests with the cookie are routed to the same backend server for processing.
- Application cookie: The application deployed on the backend server generates a cookie after receiving the first request from the client. All requests with the cookie are routed to this backend server.
Sticky sessions at Layer 7 will be invalid in the following scenarios:
- If requests sent by the clients do not contain a cookie, sticky sessions will not take effect.
- Requests from the clients exceed the session stickiness duration.
- You can set the stickiness duration only if you select Weighted round robin as the load balancing algorithm.
- The default stickiness duration is 20 minutes, and the maximum duration is 1440 minutes (that is, 24 hours).
Shared load balancers support three types of sticky session, including Source IP address, Load balancer cookie, and Application cookie.
Classic load balancers support two types of sticky session: Source IP address and Load balancer cookie.
Enabling Sticky Sessions
- Log in to the management console.
- In the upper left corner of the page, click
and select the desired region and project. - Click Service List. Under Network, click Elastic Load Balance.
- Locate the load balancer and click its name.
- For a shared load balancer, click Backend Server Groups, locate the backend server group, and click
on the right of its name. For a classic load balancer, click Listeners, locate the listener, and click Modify in the Operation column.
- Enable Sticky Session, select the sticky session type, and set the session stickiness duration.
- Click OK.
Last Article: Load Balancing Algorithms
Next Article: Access Control
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.