Multiple Data Centers for your Rails App: Caches

So you have a Rails Application. And you decide that you don’t want to be the chum who puts all his eggs in one basket and every time your data center goes down. Luckily for you, there’s some cost-effective solutions to move you closer to your goal of 99.99% uptime.

Today we’ll answer the question-How can I have a cache that works in all of my data centers?

A terrible answer would be to just have a cache in one data center and access it from another datacenter. It would ruin any and all performance you gain from caching and most likely kill your performance in general. Why? Latency. You’re adding an HTTP call to a far off data center, and you’re likely hitting it several times per web request you’re handling.

A less terrible answer would be to have two separate caches-one in each data center. This works, but things like Rails.cache.clear will need to be run in both data centers. And you run the risk of the caches getting out of sync, making your results confusing especially if someone happened to hit both data centers (one goes down in the middle of their session). From a simplest workable solution, this would be it.

What I consider to the “best” answer that gives you a single cache, distributed and functioning across multiple data centers is Couchbase. Couchbase is accessed the same way you would Memcache, but they provide an intuitive GUI to setup and manager your cluster of cache servers. As far as ease of use goes, it’s definitely the easiest. Replication has never been so easy…

Leave a Reply

Your email address will not be published. Required fields are marked *