In this lesson, you will learn how distributed Redis clusters maintain a consistent map of where data lives across multiple nodes.
When you scale a database horizontally using sharding, you break your data into pieces. In a Redis cluster, these pieces are called hash slots. There are exactly 16,384 slots available. To find out where a specific piece of data resides, the system applies a CRC16 algorithm to the key and performs a modulo operation: slot = CRC16(key) % 16384.
The Slot Mapping Table
Every node in the cluster keeps a "cluster state" map. This map acts as a directory, telling the system which node is responsible for which range of slots. Because nodes are constantly communicating via the Gossip Protocol, they stay synchronized about the cluster’s topology.
If you send a request for a key to a node that doesn't hold the corresponding slot, the node won't just fail; it will issue a MOVED redirection. This error tells your client: "I don't have that data, but node X does."
Node Communication
The cluster topology isn't static—nodes join, leave, or fail. The Gossip Protocol allows nodes to exchange information about their health and their slot assignments in the background.
Client -> Node A (Key X)
Node A -> Check Hash Slot Table
Node A -> "MOVED 12345 192.168.1.5:6379"
Client -> Node B (192.168.1.5) -> Success!
By keeping this mapping decentralized, the cluster avoids a "single point of failure" metadata server. If a master node goes down, the cluster detects the failure, initiates a failover (promoting a replica), and updates the slot mapping table across all remaining nodes. Your application client eventually updates its own internal map of these slots, ensuring that future requests hit the correct node on the first try.
Managing this topology is the secret sauce that allows a distributed system to look like a single, seamless database to your application, even as individual nodes come and go.
Key Takeaway: Cluster topology relies on a fixed set of hash slots and a gossip-based communication protocol to ensure nodes stay synchronized on where specific data segments reside.