Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RoR Cookies using ActiveRecordStore + Sticky Sessions

I have a RoR web app (w/ mysql) that is load balanced on several identical servers. The application requires cookies and sessions to function.

Currently a client is always routed to the same server behind the load balancer, and if the server is taken down, the client would be routed to a different server, and their session would end.

The current architecture's Load balancer will only load balance machines in the same data center. I would like to use multiple data centers to load balance geographically using DNS round robin, and to provide additional redundancy.

If I was to turn on ActiveRecordStore for Session storage in my RoR app, this should solve the problem above, the client could be routed to every single server and their session would be intact. Is this correct?

Are there severe ramifications of using ActiveRecordStore for sessions?

like image 996
Bill Avatar asked Nov 24 '12 22:11

Bill


People also ask

What is sticky session cookies?

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 for the duration of the session.

What are the issues with sticky session?

Since requests for a user are always routed to the same machine that first served the request for that session, sticky sessions can cause uneven load distribution across servers.

What are sticky sessions used for?

However, you can use the sticky session feature (also known as session affinity) to enable the load balancer to bind a user's session to a specific target. This ensures that all requests from the user during the session are sent to the same target.

What is sticky session in f5 load balancer?

Persistence—otherwise known as stickiness—is a technique implemented by ADCs to ensure requests from a single user are always distributed to the server on which they started. Some load balancing products and services describe this technique as “sticky sessions”, which is a completely appropriate moniker.


1 Answers

Quick answer: Given that all servers from all data centers talk to the same database, yes, this would solve the problem you have.

Ramifications: The obvious problem here would be that all servers from different data centers communicate to one data center with the database. Which is quite inefficient, because it negates most gains from distributing your app to different data centers. You could of course try to replicate mysqls over the internet, but that likely leads to data only being eventually consistent, meaning that when switching servers, the users might still face invalid sessions.

Alternative: A globally distributed store for your sessions, sort of like a cassandra ring or maybe riak would probably work better because these databases are designed to stay in sync and provide consistent access to data.

like image 69
CMW Avatar answered Sep 24 '22 10:09

CMW