Understanding Redis Cluster: Architecture, Slot Sharding, Node Management, and High Availability
Redis Cluster is a distributed system that partitions its keyspace into 16,384 hash slots across up to 16,384 nodes, enabling automatic sharding, slot migration, replication, and high‑availability features such as automatic node discovery, master‑slave election, and online resharding without service interruption.
Redis Cluster provides a way for multiple Redis nodes to share data in a distributed environment. The cluster’s keyspace is divided into 16,384 hash slots, and the maximum number of nodes is also 16,384.
Relationship hierarchy: cluster > node > slot > key.
Unlike consistent hashing, Redis Cluster uses hash slots for sharding. Each key is mapped to one of the 16,384 slots using the formula slot = CRC16(key) % 16384 , where CRC16 computes the key’s checksum.
By assigning different numbers of slots to each node, the data load and request volume can be balanced across the cluster.
Example of a three‑node cluster with evenly distributed slots:
Node A (port 6381) holds slots 0‑5499.
Node B (port 6382) holds slots 5500‑10999.
Node C (port 6383) holds slots 11000‑16383.
Adding or removing nodes is straightforward: when a new node D is added, some slots are moved from A, B, and C to D; when a node is removed, its slots are redistributed to the remaining nodes. Slot migration does not stop service, so the cluster remains available.
Data migration involves moving both slots and the keys they contain, which is essential for linear scaling and smooth expansion or contraction. During migration, a slot on the source master appears as MIGRATING , while on the target master it appears as IMPORTING . After migration, the node mapping is refreshed.
Key‑space migration transfers the keys of the migrating slots from the source master to the target master, after which the node’s mapping is updated.
Redis Cluster also includes built‑in replication and high‑availability features:
Automatic node discovery.
Slave‑to‑master election for fault tolerance.
Hot resharding (online sharding).
Cluster management via configuration files (e.g., nodes-port.conf ).
Clients connect directly to Redis nodes without an intermediate proxy.
All nodes inter‑communicate using a binary protocol optimized for speed and bandwidth.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.