Sunday, June 17, 2012

Redis - vertical scaling (migrating to large machine)

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. (

I am talking w.r.t v 2.4.14

The latest configuration suggests all the data should be in memory and we should not use Virtual Memory. So if your product is growing one day you would need to vertically scale redis (i.e. move to a large memory machine).

There are tricks for Memory Optimization. Also one can prefer sharding (keeping data divided in different redis servers based on key group). Handling expiry time wisely is another important consideration.

We followed the following approach to migrate with 0 down time!

We had two small machines (master - slave).

Cerated two large machines and set up master - slave.

With latest version of redis we can have a chain of master slaves

Master - slave1 - slave2 ..

Slave2 listens to slave1.

Put the new master as slave to old slave and let it sync. Verified the total number of keys. (Note the sync starts with some delay)

After that was done switched the new machine as the master redis in application configuration files and we were good to go. Remove the new master being slave of the old slave. Thanks to redis for all this support!

So writing to a slave is allowed :)

In case it your redis does not support slave to a slave then we can do something like this

run 'SLAVEOF NO ONE' in the old slave and on the new master run 'SLAVEOF <old master> <port>'
Once the sync is complete switch to new master and stop it being slave of the old master. Add a new slave to the new master.


No comments: