IRInterview Ready
← System Design

Consistent Hashing

Distribution & Partitioning

A hashing scheme that minimizes data movement when nodes are added or removed from a distributed system.

Consistent hashing maps both data keys and server nodes onto the same circular hash space (a 'ring'). A key is owned by the first node found walking clockwise from the key's hash position. When a node is added or removed, only the keys between it and its neighbor need to move — not the entire keyspace, unlike naive `hash(key) % N` where changing N reshuffles almost everything. Virtual nodes (each physical node gets many points on the ring) are used to smooth out load distribution.

How it connects

Consistent Hashing as the source, with the components it typically interacts with.

Load balancers use consiste…Sharded databases and distr…Distributed cache clusters…Consistent HashingDistribution & PartitioningLoad BalancerTraffic ManagementDatabase Types (SQL,NoSQL & Beyond)StorageCachingPerformance
  • Load Balancer: Load balancers use consistent hashing to pick a backend from a client key so repeated requests land on the same server for cache locality.
  • Database Types (SQL, NoSQL & Beyond): Sharded databases and distributed caches use consistent hashing to map keys to nodes with minimal data movement on scale-out/scale-in.
  • Caching: Distributed cache clusters hash keys onto a ring of nodes so only ~1/N of keys move when a node is added or removed.