Replication with Consistent Hashing
You'll learn how consistent hashing naturally determines replica placement by walking clockwise around the hash ring.
The Core Idea
When using consistent hashing, replication follows a simple geometric rule: store N replicas of each key on the next N distinct physical nodes encountered moving clockwise from the key's position on the ring.
This means if a key hashes to position 147° on the ring, and you need 3 replicas (N=3), you walk clockwise and place copies on the first three different physical servers you encounter.
Why This Works Beautifully
The clockwise rule gives you:
- Automatic replica distribution: No central coordinator needed to decide where replicas live
- Predictable lookup: Any node can calculate where replicas should be by performing the same clockwise walk
- Graceful node changes: When nodes join or leave, only adjacent replicas are affected
The "Distinct Physical Nodes" Requirement
This is critical. Since virtual nodes exist (from lesson 1463), you might encounter multiple virtual nodes belonging to the same physical server as you walk clockwise. You skip these and continue until you've found N different physical machines.
Think of it like assigning backup keys to neighbors: you wouldn't give all three backup house keys to the same neighbor, even if they live in multiple apartments on your street.
Practical Example
Key "user:42" hashes to 100° on the ring. With N=3 replication:
- Walk clockwise from 100°
- First physical node at 120° → Replica 1
- Second physical node at 185° → Replica 2
- Third physical node at 240° → Replica 3
Key Takeaway: Consistent hashing determines replica placement by storing copies on the next N distinct physical nodes clockwise from the key's ring position, enabling automatic, decentralized replication without coordination overhead.