What is Redis Cluster?
Redis is an open-source, in-memory data structure store that is used to build caches and key-value NoSQL databases. Redis Cluster is a special version of Redis that helps improve the scalability and availability of your Redis database. But what is Redis Cluster exactly, and how is Redis Cluster different from Redis?
What is Redis Cluster? How is Redis Cluster different from Redis?
Redis Cluster is a distributed implementation of Redis that automatically shards (i.e. partitions) data across multiple Redis nodes.
No one can predict the exact amount of resources their Redis database will consume. This means that being able to adequately scale your Redis database is crucial during periods of high demand. Scalability goes hand-in-hand with availability, a metric that measures users' ability to actually access the database.
Redis Cluster helps improve the scalability, availability, and fault-tolerance of Redis databases, beyond the base version of Redis. The features of Redis Cluster include:
- Scalability: Redis Cluster can scale out to a maximum limit of 1000 nodes.
- Availability: There are two conditions for a Redis cluster to continue operating: the majority of master nodes must be reachable, and any master node that is unreachable must have a backup slave node. This is a generous policy that helps improve the availability of your Redis database.
- Write safety: Redis Cluster attempts to behave in a write-safe manner: it will try to preserve the writes from any client connected to the majority of master nodes in the cluster.
How does Redis Cluster work?
Redis Cluster works by sharding the data in a database. Sharding is a database partitioning scheme in which different rows in a database (or, in the case of Redis, key-value pairs) are distributed across multiple nodes, so that each node contains a portion of the data. This means that if one node goes down, only a portion of the data will be unavailable, which will allow many database requests to proceed as normal.
Another important concept in Redis Cluster is the master/slave architecture. In this pattern, one node is designated as the "master," which controls and coordinates the remaining nodes in the cluster (known as the "slaves" or the "replicas").
Redis Cluster can use master-slave replication, so that each master in the cluster has a backup slave node. If one of the master nodes fails, the corresponding slave node can be designated the new master, with little disruption to the overall cluster. (If both the master and slave nodes fail, however, the entire cluster will not be able to keep operating).
Note that although Redis Cluster attempts to provide a high level of write-safety, it cannot guarantee strong consistency. This is largely because Redis Cluster uses asynchronous replication. If a client writes something to the master node, which then crashes before replicating the write to its slave nodes, then the new master node (the promoted slave node) will have no knowledge of this write. Instead, Redis Cluster attempts to strike a balance between high performance and consistency.