Wednesday, February 02, 2022

Scalability in Redis using Sentinel and Cluster approach

 Scalability for Redis is one of the important USP for selling. In Redis as it is distributed multi datatype support highly available nosql data it is mandate for Redis to give high scalability in comparision of other nosql db along with good speed and cache first management.

In redis scalability can be done using two basic concept
1- Sentinel
2- cluster using Sharding

1- Sentinel :-

Sentinel provides high availability for your system if you have single redis instance and that instance goes down for some reason you are pretty much in trouble because your application depends on rediss storeed data and if your data source is down your application is of no use. To resolve this issue you could add slaves to duplicate your master and then just read it from the slaves until your master comes up again. This is one way to do it and is more reliable way to do that simply use sentinel.

In short we can say its a solution that makes it easier to manage Redis instances. Sentinel is a separate application that runs in the background. It will monitor your master and slave instances, alert you to any changes, manage automated failover in the event of a master failure, and perform as a configuration provider.

The primary purpose of using sentinel is to provide a highavailability system by monitoringnotifying and providing instancefailover

sentinel performs the threetasks
1- monitoring: In this step sentinel check if the master and slave instances are working as expected
2- notification: In this step sentinel notify other programs or other system administrators thorugh an API when there is something wrong with the monitoringinstances
3- automatic failover: In this step sentinel on a master failure promotes one of the slaves to become the new master and then make the other additional slaves use the new master. In additoin sentinel acts as the source of authorityfor clients clients connect to sentinel in order to ask for the address of thecurrent raddest master

Quorum is configurable which only refers to the number of sentinels who must agree when a master is down. When in a failover scenario, sentinel instances attempt to reach a consensus, and at least three (odd number) sentinel instances will prevent most problems. These three Sentinel instances can be in the same master redis server or better they should also be placed on separate physical servers or Virtual Machines, as they are expected to fail in independent ways.

Now lets check how the redis sentinel work.

as we know we have redis client who sent the Redis master request and now if the master node died for some reason we automatically connect to slaves to serve as a new master.sentinels come as another layer in front of raddis master so basically we set upadditional servers for example Sentinel one, Sentinel two and Sentinel three all these instance of Sentinel server are used to monitor master and slaves nodes these sentinels communicate between each of them and they also communicate with the master and the slaves nodes. Now when the request comes from the client it goes first The Sentinel and the Sentinel act as the source of authority and tells which master is in action the responsibility of sentinels to detect when master goes down and depending on your settings of the quorum
which is the value represents the number of Sentinel that seems to agree that Master is not reachable let’ssay column is set to two which means weneed two sentinelsfor example center one and Sentinel two agree if master nodes is down if this isthe case they elect new master by picking one of the slaves and promoting it to master. Now once the old master is up and running again the data gets synced back again. Few things to consider when working with sentinels it’s recommended to have atleast three Sentinel instances to run onservers that fail in an independent way though it’s not necessary to run the Sentinel nodes onseparate servers they can be run asparallel processes on the redis nodes themselves.

While working with seninel you mush agree that redis client should support them as they are going to consum the snetinel api.Sentinel itself is nothing more than a specific execution mode of the Redis server itself rather Sentinel has a set of api’s that provideinformation on the running instances forexample you can run a specific commandlike Sentinel masters would show a list of monitored masters and their states.

2- cluster using Sharding

redis cluster a stable version mandate to have minimum three node master and 2 node slave cluster with data sharding solution with automatic management failover and replication. Data sharding is a method to break up a big database into many smaller parts called as data set. It is the process of breaking up a database across multiple machines to enhance the manageability availability performance and load balancing of an application the reason for data sharding is that after a certain scale point is cheaper and more attainable to scale horizontally by adding more machines than to grow it vertically by adding more servers. Generally cluster mode provides similar high availability than sentinel mood . Cluster improve the scalability of your application as data continued to grow. Like sentinel there is no dedicated monitoring facility every Redis cluster node requires two TCP connections open the standard redis TCP port used to serve clients and another port to have communication between master and slave nodes.this is called cluster bus. For failure detection configuration update failover authorization and so forth the cluster maintains this state by itself let’s assume this is a cluster of three masters each master has one slave which used to replicate the master all notes communicate with each other through the cluster bus.

Please refer more on belwo site and redis documentation.

so in short

If you want to use Redis for testing, but don’t need high availability or data-reliability -> Use Standalone Redis
If you need high availability, even if it is not scalable, and you have less data than RAM on a machine -> Use Redis Sentinel
If You need data sharding, scalability and automatic failover, it doesn’t have to be entirely highly available and you have more data than RAM on a server -> Use Redis Cluster

No comments: