Consistent hashing explained in plain terms means understanding how a distributed system decides which server owns each piece of data, without moving everything when a server joins or leaves. The central question is how thousands of keys can be spread fairly across many machines, and the answer is a circle, called a hash ring, on which both servers and keys are placed by the same hash function.
Consistent hashing is a way of assigning data to servers that keeps most assignments stable when the set of servers changes. Instead of dividing keys by the number of servers, which would shuffle nearly every key whenever a machine is added or removed, it maps each key to the next server clockwise around the ring, so only the keys near the change need to move.
The idea matters because distributed systems grow and shrink all the time. Servers fail, new capacity is added at busy times, and caches are replaced, yet users expect their data to stay reachable and their cached pages to stay warm. This article explains what consistent hashing is, how it works, and where it is used.
Key takeaways
- Consistent hashing places servers and keys on the same hash ring.
- Each key belongs to the first server clockwise from its hash position.
- Adding or removing a server moves only the keys near that server.
- Virtual nodes spread each server around the ring to balance the load.
- Replication copies each key to the next servers for fault tolerance.
What consistent hashing is
Consistent hashing is a placement rule for distributed storage and caching. A hash function turns every server name and every key into a number, and those numbers are treated as positions around a circle. A key is stored on the first server met when moving clockwise from the key’s position, which gives every key a single owner without a central directory to consult.
The method was described by Karger and colleagues in 1997, in work on web caching, and it has since become a standard building block for distributed systems. Its appeal is that the mapping is deterministic: any machine that knows the ring and the hash function can work out where a key lives, so lookups need no extra hop to a coordinator or a lookup table.
Because the ring is shared, a new server only takes over the keys that fall between it and its predecessor, while every other key stays where it was. That property is what makes the method consistent, and it is why it suits systems that change size often. Our guide to distributed systems explains the wider problem of coordinating many machines, and our guide to sharding explains the related idea of splitting a dataset across servers.
How consistent hashing works
The process starts with a hash function that produces a large range of values, such as a 128-bit or 160-bit space, imagined as a circle where the largest value wraps back to the smallest. Each server is hashed, often several times, and each result marks a point on the ring. Each key is hashed in the same way, and its position on the ring decides its owner.
To find a key, the system walks clockwise from the key’s position until it reaches a server point, and that server is responsible for the key. If the walk passes the end of the range, it wraps to the start, so every key has an owner even when it hashes to a point beyond the last server. The rule is simple enough to compute in a fraction of a millisecond.
When a server joins, it is hashed onto the ring and takes over the keys between its position and the previous server’s position. Only those keys are copied to the new machine, and the rest of the system is untouched, which means a scale-out can happen without a long pause while data is reshuffled. When a server leaves or fails, its keys pass to the next server clockwise, again with no wider disturbance.
Virtual nodes make the balance fairer. A real server is given many points on the ring, called virtual nodes, spread evenly around the circle, so each machine owns many small slices rather than one large arc. If one server happens to land on a long empty stretch, its other virtual nodes still give it a fair share, and when a machine is removed, its load is spread across many neighbours instead of falling on one.
Replication is usually layered on top. Instead of storing a key on one server only, the system copies it to the next one or two servers clockwise as well, so a failure does not make the data unreachable. The first server is the primary owner, and the copies act as standbys, which also lets reads be shared among the replicas when the primary is busy.

Comparing consistent hashing with other placement methods
Consistent hashing is one of several ways to decide where data lives, and each suits a different need. Simple modulo hashing is easy but reshuffles almost everything on a change, a central directory is flexible but adds a single point of failure, and random placement is simple but makes lookups hard to predict.
The table below sets out the main contrasts between the leading approaches.
| Aspect | Consistent hashing | Modulo hashing | Central directory |
|---|---|---|---|
| Placement rule | Next server clockwise | Key divided by server count | Lookup in a table |
| Keys moved on change | Only those near the change | Nearly all keys | Only the moved keys |
| Lookup cost | Hash and walk the ring | One hash and division | One directory query |
| Single point of failure | None, if the ring is shared | None | The directory itself |
| Best for | Growing caches and stores | Fixed small clusters | Flexible, managed placement |
The practical result is that consistent hashing is the right choice when servers come and go, modulo hashing suits a fixed set of machines, and a central directory wins when placement needs human control or unusual rules.
Where consistent hashing is used
Distributed caches are the classic use. Systems such as Memcached and similar caches spread cached entries across many servers with consistent hashing, so adding a cache server warms only a small share of the cache, and a failed server loses only its own slice rather than forcing a full reload from the database behind it.
Distributed databases use the same idea for their data. Dynamo-style stores, including Amazon DynamoDB and Apache Cassandra, partition their key space around a ring, so each node owns a range of keys and replication follows the ring as well. The design lets these systems grow by adding nodes without taking the whole database offline.
Content delivery networks use consistent hashing to choose which edge server serves a request. A request for a particular object is routed to the same edge server each time, which keeps that object in the server’s cache, and when an edge server is added or removed, only nearby objects are reassigned to a different server.
Load balancers and request routers use it to keep related traffic together. A user session, a websocket connection, or a stream of events can be pinned to the same backend server by hashing an identifier, which keeps session state local, while a new backend still only takes over a small share of the traffic.
Object storage and peer-to-peer systems use it too. Large stores spread objects across disks and machines by hashing their names, and peer-to-peer networks use the ring to let each participant find the node responsible for a file without a central index, which keeps the system working as peers join and leave.
Strengths and limits
The greatest strength of consistent hashing is stability under change. Adding or removing a server disturbs only a small fraction of the keys, which keeps rebalancing fast and cheap, and lets a system scale in small steps rather than in disruptive leaps that pause service while data moves.
It is also a strength that the method needs no central coordinator. Every node that knows the ring can locate any key on its own, which removes a single point of failure and keeps lookups fast, and virtual nodes make the load surprisingly even across machines of different sizes, since a larger server can simply be given more virtual nodes.
The limits are real, though. The load is only roughly even, never exact, and a badly chosen hash function or too few virtual nodes can leave one server overloaded. The method also says nothing about how replicas stay in sync, how failures are detected, or how a key is found when the ring itself is out of date on some nodes, so those problems need separate mechanisms.
Consistent hashing checklist
- Choose a hash function with a wide, even output range.
- Use enough virtual nodes to keep the load even.
- Give larger servers more virtual nodes than smaller ones.
- Replicate each key to the next servers clockwise.
- Copy only the affected keys when a server joins or leaves.
- Monitor the load per server, not just the average.
- Plan how clients learn about ring changes.
- Test what happens when a server fails mid-rebalance.
- Measure cache hit rates after each scale-out.
Frequently asked questions
What is consistent hashing in simple terms?
It is a way of sharing data across servers using a circle called a hash ring. Servers and keys are both placed on the ring by hashing, and each key belongs to the first server clockwise from it, so a change to the servers moves only a few keys.
Why is it called consistent?
It is called consistent because the mapping stays mostly the same when servers are added or removed. Unlike dividing by the number of servers, which reshuffles nearly every key, consistent hashing keeps most keys on the same server they were on before.
What is a virtual node?
A virtual node is one of many points on the ring that represent a single real server. Giving each server many virtual nodes spreads its share into small slices around the ring, which evens out the load and spreads the work of a failed server across many neighbours.
What happens when a server fails?
Its keys pass to the next server clockwise on the ring, and replicas held by the following servers take over serving them. The rest of the system is unaffected, and when the server returns or is replaced, the keys move back in the same limited way.
How is consistent hashing different from sharding?
Sharding is the general idea of splitting a dataset across servers, while consistent hashing is one method for deciding which shard a key belongs to. A sharded system can use consistent hashing, modulo hashing, or a directory to make that decision.
Where is consistent hashing used in practice?
It is used in distributed caches, Dynamo-style databases such as Cassandra, content delivery networks, and load balancers. Any system that must grow or shrink without reshuffling all of its data is a likely candidate.
The bottom line
Consistent hashing explained in one line is this: put servers and keys on one ring, give each key to the next server clockwise, and a change to the servers will disturb only the keys nearest to it.
It is a small idea with a large effect, and it is the reason many distributed systems can grow, shrink, and recover without pausing to move all of their data at once.
This article is general information about how consistent hashing works, not advice about designing a distributed system for a particular workload.







