RoR Cookies Using ActiveRecordStore + Sticky Sessions

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

Currently, the client is always routed to the same server behind the load balancer, and if the server is deleted, the client will be redirected to another server and their session will end.

Current architecture The load balancer will only load balance machines in one data center. I would like to use several data centers to geographically distribute the load using DNS round robin and provide additional redundancy.

If I enabled ActiveRecordStore to store the session in my RoR application, this should solve the problem above, the client can be redirected to each individual server, and their session will be intact. Is it correct?

Are there any serious implications of using ActiveRecordStore for sessions?

+6
source share
1 answer

Quick answer: Given that all servers from all data centers are talking to the same database, yes, that would solve your problem.

Branches: The obvious problem here is that all servers from different data centers will connect to a single data center with a database. This is pretty inefficient because it denies the big benefits of distributing your application to different data centers. Of course, you could try to replicate mysqls over the Internet, but this will probably lead to the data being eventually consistent, which means that when switching servers, users may still encounter invalid sessions.

Alternative: A globally distributed store for your sessions, such as a cassandra ring or perhaps riak, will probably work better because these databases are designed to synchronize and provide constant access to data.

+4
source

All Articles