What is consistent hashing?
Answer
Consistent hashing is a technique for distributing data across a cluster of nodes such that adding or removing nodes requires remapping only a minimal fraction of keys. Problem it solves: with simple modulo hashing (key % N), adding or removing one server causes almost all keys to remap — triggering massive cache invalidation or data migration. How it works: imagine a circular ring (hash space) with values 0 to 2³²-1. Each server is hashed to a position on the ring. Each key is also hashed to a position. A key is assigned to the first server encountered going clockwise on the ring. Adding a server: only keys between the new server and its predecessor on the ring are affected — roughly 1/N of total keys. Removing a server: its keys move to the next server clockwise — only 1/N affected. Virtual nodes (vnodes): each physical server is mapped to multiple positions on the ring. Benefits: more uniform distribution (avoids hot spots); smoother addition/removal; different server capacities handled by assigning proportionally more vnodes. Real-world use: Memcached client-side sharding, Cassandra ring topology, DynamoDB (originally), Riak, Chord DHT, Akamai CDN. Applications: distributed caching, database sharding, load balancing. Consistent hashing is one of the most important concepts in distributed systems design.