Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis advantages of Sentinel and Cluster

I'm planning to create a high available Redis Cluster. After reading many articles about building Redis cluster i'm confused. So what exactly are

  • the advantages of a Redis Sentinel Master1 Slave1 Slave2 Cluster? Is it more reliable as a Redis Multinode Sharded Cluster?
  • the advantages of a Redis Multinode Sharded Cluster? Is it more reliable as a Redis Sentinel Master1 Slave1 Slave2 Cluster?

Further questions to the Redis Sentinel Master1 Slave1 Slave2 Cluster:

  • when i have 1 Master and the two Slaves and traffic is getting higher and higher so this cluster will be to small how can i make the cluster bigger?

Further questions to the Redis Multinode Sharded Cluster:

  • why are there so many demos with running a cluster on a single instance but on different ports? That makes no sense to me.
  • when i have a cluster with 4 masters and 4 replicas, how can an application or a client be sure to write to the cluster? When Master1 and Slave1 are dying but my application is writing always to the IP of Master1 then it will not work anymore. Which solutions are out there to implement a sharded cluster well to make it available for applications to find it with a single ip and port? Keepalived? HAproxy?
  • when i juse for a 4 master setup with e.g. Keepalived - doesn't that cancel out the different masters?
  • furthermore i need to understand why the multinode cluster is only for solutions where more data will need to be written as memory is available. Why? For me a multi master setup sounds good to be scaleable.
  • is it right that the the sharded cluster setup does not support multikey operations when the cluster is not in caching mode?

I'm unsure if these two solutions are the only ones. Hopefully you guys can help me to understand the architectures of Redis. Sorry for so many questions.

like image 397
Pegasus1985 Avatar asked Dec 14 '22 11:12

Pegasus1985


1 Answers

I will try to answer some of your questions but first let me describe the different deployment options of Redis. Redis has three basic deployments: single node, sentinel and cluster.

  • Single node - The basic solution where you run single process running Redis. It is not scalable and not highly available.
  • Redis Sentinel - Deployment that consist of multiple nodes where one is elected as master and the rest are slaves. It adds high availability since in case of master failure one of the slaves will be automatically promoted to master. It is not scalable since the master node is the only node that can write data. You can configure the clients to direct read requests to the slaves, which will take some of the load from the master. However, in this case slaves might return stale data since they replicate the master asynchronously.
  • Redis Cluster - Deployment that consist of at least 6 nodes (3 masters and 3 slaves). where data is sharded between the masters. It is highly available since in case of master failure, one of his slaves will automatically be promoted to master. It is scalable since you can add more nodes and reshard the data so that the new nodes will take some of the load.

So to answer your questions:

  1. The advantages of Sentinel over Redis Cluster are:
    • Hardware - You can setup fully working Sentinel deployment with three nodes. Redis Cluster requires at least six nodes.
    • Simplicity - usually it is easier to maintain and configure.
  2. The advantages of Redis Cluster over Sentinel is that it is scalable.

The decision between that two deployment should be based on your expected load. If your write load can be managed with a single Redis master node, you can go with Sentinel deployment.

If one node cannot handle your expected load, you must go with Cluster deployment.

  1. Redis Sentinel deployment is not scalable so making the cluster bigger will not improve your performance. The only exception is that adding slaves can improve your read performance (in case you direct read requests to the slaves).

  2. Redis Cluster running on a single node with multiple ports is only for development and demo purposes. In production it is useless.

  3. In Redis Cluster deployment clients should have network access to all nodes (and node only Master1). This is because data is sharded between the masters. In case client try to write data to Master1 but Master2 is the owner of the data, Master1 will return a MOVE message to the client, guiding it to send the request to Master2. You cannot have a single HAProxy in front of all Redis nodes.

  4. Same answer as in 5, in the cluster deployment clients should have direct connection to all masters and slaves not through LB or Keepalived.

  5. Not sure I totally understood your question but Redis Cluster is the only solution for Redis that is scalable.

  6. Redis Cluster deployment support multikey operations only when all keys are in the same node. You can use "hash tags" to force multiple keys to be handled by the same master.

Some good links that can help you understand it better:

Description on the different Redis deployment options: https://blog.octo.com/en/what-redis-deployment-do-you-need

Detailed explanation on the architecture of Redis Cluster: https://blog.usejournal.com/first-step-to-redis-cluster-7712e1c31847

like image 60
Elad Tamary Avatar answered Dec 16 '22 00:12

Elad Tamary