linkjobai / Consistent Hashing Explained for System Design Interviews
0 likes
0 forks
1 files
Last active
Interview prep notes
Consistent Hashing Explained for System Design Interviews
When you shard a cache or database with hash(key) mod N, adding or removing one server remaps almost every key. Consistent hashing limits the damage to roughly 1/N of the keys.
How it works
- Map servers and keys onto the same ring of hash values (for example 0 to 2^32 - 1).
- A key belongs to the first server clockwise from its position.
- When a server joins, it takes keys only from its clockwise neighbour; when one leaves, its keys move to the next server.
Newer
Older