In our recent posts, we talked about Redis clusters and different operations around it. There is another mode in which Redis can run and this mode is master-slave. In this article, we are going to talk about is Redis master-slave and Redis clusters, and the difference between them?
Redis Master-Slave
In this mode, there are a set of nodes that are masters and a set of nodes that are slaves or replicas. They are generally in pairs and slaves replicate the masters.
The client can read and write to masters and only read from slaves. The other masters are in sync with this one so that in case of failure of the main master the other ones can take its place and start serving. This is generally not used as it is a very costly setup.
Instead what people use are 1 master and multiple slaves and once the master goes down the slave is promoted as master and the master will be changed to a slave once it comes back.
How does failover work?
There can be two scenarios either a master going down or a shard going down, let’s consider them one by one.
Master Failure
In this scenario, there can be two cases. If you have hot standby master you can promote it to master and the replica of the older master will be converted to master but now it is a hot standby.
Another case is your replica will be promoted to master and once the old node is fine it will take up the role of the replica.
Slave Failover
This case is very simple. There is no failover here. There will be just slave reboot and partial or full sync with the master.
Redis Cluster
Clustering is different that master-slave in a very basic sense that not all the data of the cluster resides on one node. There are multiple master nodes where data will reside and each master has a different group of data which is called a shard. There are 16384 shards divided among the total number of masters. Each master has replicas and when the master goes down the replica takes over as master.
Cluster is very effective on a high scale especially when the writes are your problem.
How failover works in a cluster
In the case of cluster whenever a node fails it again can be of two types master or replica. In the case of master failure the replica will take up the role of master and the cluster will keep working.
In case of replica failure, there is no impact the slave will reboot and them does partial or full sync and then again start working as a replica.
When to use master-slave or clustering?
In easy terms, we can say whenever there is an amount of data that cannot fit your ram you can shard it and save it in the cluster. So when the amount of data is more than ram of single-node use cluster. Otherwise, you can use a master-slave. Also, note that sharding can also help to scale your writes on Redis.
This was what is Redis master-slave and Redis clusters and the difference between them? Stay updated for more such articles. Share and subscribe.
1 COMMENT
Excellent