Consistent Hashing
💡 The Core Idea
In a distributed system (like a CDN cluster), we need to map content to specific servers. Traditional hashing () fails because if changes (server failure/addition), all keys must be remapped. Consistent Hashing minimizes this disruption.
🧠Mechanism
- The Ring: Map both Servers and Content to the same circular ID space (e.g., 0 to ) using a hash function.
- Assignment: A piece of content is assigned to the next server encountered moving clockwise on the ring.
- Resilience:
- Node Joins: Only keys falling in the gap before the new node need to move to it.
- Node Leaves: Only keys belonging to the failed node move to the next successor.
- Result: Minimizes data movement, maintaining load balance.