Redis & Caching (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How does Redis Cluster partition data across 16,384 Hash Slots?
senior LevelCode ExampleredisAdvanced Internals
In Simple Words: Redis Cluster provides transparent, distributed horizontal sharding with zero single point of failure:
- The keyspace is divided into 16,384 Hash Slots (0 to 16,383).
- Slot Calculation: $$\text{Slot} = \text{CRC16}(key) \pmod{16384}$$
- The 16,384 slots are divided among master nodes (e.g. Node 1 owns 0-5460, Node 2 owns 5461-10922, Node 3 owns 10923-16383).
- Clients connect to any node. If a key belongs to another node, the server responds with a
-MOVED <slot> <ip:port>redirect.
text
Redis Cluster Hash Slot Distribution:
[Client] ──► Query: "user:101"
│
CRC16("user:101") % 16384 = Slot 7200
│
┌────────┴────────┐
▼ ▼
[Node A (0-5460)] [Node B (5461-10922)] ◄── Key resides here!