Redis Cluster Sharding
You'll learn how Redis Cluster distributes data across multiple nodes using hash slots to scale horizontally beyond a single machine's memory limits.
The Core Idea
Redis Cluster solves the problem of storing more data than a single Redis instance can hold by sharding — splitting your dataset across multiple Redis nodes. Unlike manual partitioning, Redis Cluster uses a built-in hash slot mechanism to automatically distribute keys across nodes while maintaining fast lookups.
How Hash Slot Sharding Works
Redis Cluster divides the entire key space into 16,384 hash slots (numbered 0-16383). When you store a key, Redis computes a hash of the key name and maps it to one of these slots using the formula:
HASH_SLOT = CRC16(key) mod 16384
Each master node in the cluster is assigned a range of hash slots. For example, with three nodes:
- Node A: slots 0-5460
- Node B: slots 5461-10922
- Node C: slots 10923-16383
When a client requests a key, Redis calculates which slot it belongs to and routes the request to the node responsible for that slot.
The Resharding Advantage
Because slot assignments are independent of node count, you can add or remove nodes by moving hash slots between nodes — not by rehashing all keys. This is much more efficient than traditional hash-based sharding.
Horizontal Scaling in Action
Redis Cluster enables you to scale write throughput and total memory capacity by adding nodes. Each node handles a subset of keys, so your cluster's total capacity equals the sum of all nodes' memory.
Key Takeaway: Redis Cluster uses 16,384 hash slots to shard data across nodes, enabling horizontal scaling by distributing keys deterministically while allowing efficient resharding through slot migration.