In this article, I will be talking about the Redis Clustering. First of all, I like to give a brief introduction about the “Redis Clustering”.
What is “Redis”?
“Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.” — Redis Website
Redis stands for “Remote Dictionary Server” which has the ability to run in both local and cloud platforms. When simply talking about Redis, it is a key value store, which means it can store data as a pair of keys and values as well as it is an in-memory data structure store which keeps data in cache. Redis can act as a database because stored data can read or write. Redis supports data structure such as String, hashes, lists, sets and stored sets.
There are 2 options creating a distributed environment.
1. Redis Sentinel
2. Redis Cluster
What is “Redis Clustering”?
Redis cluster can be considered as an active-passive implementation which consists of master and slave nodes. The cluster uses partitioning in order to split the key space into 16,384 key slots. Hash slots are defined by Redis so the data can be mapped to different nodes in the Redis cluster.
Each master is responsible for a subset of those slots. Each slave node has a specific master and slave nodes can be reassigned to another master or be elected as a master node. Replication is completely asynchronous and does not block the master or the slave. Masters receive all requests that read and write for their slots and slaves do not communicate with clients.
As an example, a minimal cluster of 3, one node can hold the slots 0 to 5640, next node will hold 5641 to 10922, and the 3rd node holds 10922 to 16383.
Why Redis Clustering?
· There will be no need of writing queries like in SQL because Redis has a simple and straight forward data write/read and no need of SQL knowledge.
· It is trending and used in many applications and platforms such as GitHub, Weibo, Pinterest, Snapchat, Craigslist, Digg, Stack Overflow, Flickr.
· Redis is able to save costs for cloud database calls.
· It supports many languages and is developer friendly.
· It is open source and stable.
Redis clustering architecture model
Redis architecture consists of two main processes which is Redis client and Redis server. It has a client server architecture.
Redis cluster as a distributed system.
Redis can recover from component failures without performing incorrect actions. Modern databases need to be fault tolerant and resist failure as much as possible without human intervention. Though crashes are rare in Redis instances, there are error cases that can cause a failure.
- Backups and Restore
These facts are very important for fault tolerant quality of the Redis cluster.
When you are relying on a database to power a large enterprise application, downtime is unacceptable. Redis Cluster supports the standard Redis master-replica configuration to ensure high availability and durability. It also implements a Raf-like consensus approach to ensure availability of the entire cluster. Redis Cluster is able to survive partitions where the majority of the master nodes are reachable and there is at least one reachable slave for every master node that is no longer reachable. Using replicas migration, masters no longer replicated by any slave will receive one from a master which is covered by multiple slaves
1. Write Consistency guarantees
3. Clustering & Sharding
4. Load Balancing
These four facts are mainly important for high availability of Redis clustering.
Recoverable means failed components can restart themselves and rejoin the system, after the cause of failure has been repaired. When we talk about the Redis clusters and its recoverable, Then Redis Cluster will perform an automatic failover process and the relevant Slave becomes and works as the Master.
Redis Cluster is not able to guarantee strong consistency. In practical terms this means that under certain conditions it is possible that Redis Cluster will lose writes that were acknowledged by the system to the client. The first reason why Redis Cluster can lose writes is because it uses asynchronous replication.
Scalability can be considered as one of the main goals of Redis clustering. It has linear scalability up to 1000 nodes. With Sharding or Partitioning we are not restricted to store data on a single computer memory. Another advantage of sharding is, we can use computational power of multiple cores.
Because of the caching system in Redis Clustering performance is much predictable to applications and developers.
Redis cluster provides multi layer security configuration with access control, authentication, forensics, encryption.