There is a website run by 2 servers. These 2 servers balances the load using Load Balancer. So, if 1 session is created on 1 server and say load is shift to another server immediately, then how session is maintained?
I am just interested in the concept at a very high abstract level and not real implementation details.
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).
A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase capacity (concurrent users) and reliability of applications.
Session affinity, also known as “sticky sessions”, is the function of the load balancer that directs subsequent requests from each unique session to the same Dgraph in the load balancer pool.
To use sticky sessions, the client must support cookies. Application Load Balancers support both duration-based cookies and application-based cookies. Sticky sessions are enabled at the target group level.
This is where the concept of "Sticky Sessions" or "Session Affinity" comes into play.
http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/US_StickySessions.html
You can configure many load balancers to route user sessions to the same machine.
Another approach would be to maintain session information in a datastore accessible by both machines behind the load balancer. If the session exists in your database (or even redis/memcached) it's just a primary key query (or get
) away from being consistent on both machines.
Self promotion: I actually started a project to implement something like a session at Buzzfeed. http://github.com/buzzfeed/phonon
EDIT: updated link to personal project.
This situation depends of the technology, in my experience with .Net there are two concepts called StateServer or SQLServer which are the recommendations to get the session information out of the execution process in the servers, so that's the idea, isolate the sessions in a different server or process, you can read a little bit here:
State Server modes in .Net
Load Balancing in .Net
So additionally read this Read to get the difference between Load Balancing and Clusters, for some platforms is better to select the best option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With