What is the difference between session affinity and sticky session in context of load balancing servers?
7 Answers
I've seen those terms used interchangeably, but there are different ways of implementing it:
- Send a cookie on the first response and then look for it on subsequent ones. The cookie says which real server to send to.
Bad if you have to support cookie-less browsers - Partition based on the requester's IP address.
Bad if it isn't static or if many come in through the same proxy. - If you authenticate users, partition based on user name (it has to be an HTTP supported authentication mode to do this).
- Don't require state.
Let clients hit any server (send state to the client and have them send it back)
This is not a sticky session, it's a way to avoid having to do it.
I would suspect that sticky might refer to the cookie way, and that affinity might refer to #2 and #3 in some contexts, but that's not how I have seen it used (or use it myself)

- 2,929
- 24
- 44

- 87,846
- 14
- 132
- 192
-
7If a request is bound to a physical server, what happens if that server fails? Is there a strategy to use the cookie to contain a fail-over server? – raffian Apr 04 '13 at 20:20
-
3If the server fails, the application fails -- maybe you need to login again. Maybe you have lost data. Usually, the load-balancer picks another server and you keep going, but some state is lost. If this is unacceptable, then you need to get the state to the DB or other servers as quick as possible or have a stateless strategy. – Lou Franco Feb 05 '15 at 14:43
-
FWIW Heroku refers to them as the opposite. Session Afifinity is cookie based, and it doesn't support sticky. https://devcenter.heroku.com/articles/session-affinity – RandallB Jan 25 '16 at 20:17
As I've always heard the terms used in a load-balancing scenario, they are interchangeable. Both mean that once a session is started, the same server serves all requests for that session.

- 15,522
- 5
- 45
- 61
Sticky session means that when a request comes into a site from a client all further requests go to the same server initial client request accessed. I believe that session affinity is a synonym for sticky session.

- 113,795
- 27
- 197
- 251
They are the same.
Both mean that when coming in to the load balancer, the request will be directed to the server that served the first request (and has the session).

- 242,243
- 40
- 408
- 536
Sticky session means to route the requests of particular session to the same physical machine who served the first request for that session.

- 171
- 3
- 7
difference is explained in this article: https://www.haproxy.com/blog/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/
Main part from this link:
Affinity: this is when we use an information from a layer below the application layer to maintain a client request to a single server. Client's IP address is used in this case. IP address may change during same session and then connection may switch to different server.
Persistence: this is when we use Application layer information to stick a client to a single server. In this case, loadbalancer inject some cookie in response and use same cookie in subsequent request to route to same server.
sticky session: a sticky session is a session maintained by persistence
The main advantage of the persistence over affinity is that it’s much more accurate, but sometimes, Persistence is not doable(when client dont allow cookies like cookie less browser), so we must rely on affinity.
Using persistence, we mean that we’re 100% sure that a user will get redirected to a single server. Using affinity, we mean that the user may be redirected to the same server…

- 473
- 1
- 6
- 14
They are Synonyms. No Difference At all
Sticky Session / Session Affinity:
Affinity/Stickiness/Contact between user session and, the server to which user request is sent is retained.

- 842
- 10
- 7