Consistent Hashing in Modern Architectures
In modern architectures of microservices, distributed databases etc., systems must handle millions of keys or requests. As clusters grow or…
Consistent Hashing in Modern Architectures
In modern architectures of microservices, distributed databases etc., systems must handle millions of keys or requests. As clusters grow or shrink, the system must redistribute load while minimizing disruption.
The Core Idea Behind Consistent Hashing
Consistent hashing solves the instability of modulo-based hashing by using a circular hash space, commonly called the hash ring.
Instead of hashing keys into buckets based on server count, both servers and keys are assigned positions on the ring. A key is stored on the next server clockwise.
This structure ensures stability: only keys that mapped to a changed server need to move.
How Consistent Hashing Works (Step-by-Step)
1. Build a hash ring
A hash function (like SHA-1) maps values to a range (e.g., 0 to ²³²−1). Visualize this range as a circle.
2. Hash the servers
Each server is assigned one or more positions on the ring based on its identity (e.g., "server1").
3. Hash the keys
Each key (user ID, cache entry, record key) is also hashed onto the ring.
4. Find each key’s server
A key maps to the first server clockwise from its hash position.
5. Handle changes gracefully
- Adding a server: Only keys between the server’s previous and new position move.
- Removing a server: Its keys move to the next server on the ring.
Load Balancing Strategies
Hash values aren’t naturally uniform, so relying on a single server position can create hotspots, where one server gets disproportionately more keys. A common solution to this is virtual nodes.
Virtual Nodes (VNodes)
Hash each server multiple times into the ring:
server1#1,server1#2,server1#3, …
Each virtual node behaves like a separate server in the ring, evening out the distribution.
More replicas = smoother balancing, more memory usage and slower ring updates. Too few replicas = uneven distribution. Typical values are 100–200 per server.
Fault Tolerance and Scalability
Consistent hashing shines in dynamic environments:
Fault tolerance
If a server fails:
- Only its keys need reassignment.
- Every other server keeps its load.
Scalability
Clusters can grow organically:
- Add servers → they automatically pick up part of the load
- Remove servers → remaining ones take over seamlessly
This behavior makes consistent hashing ideal for cloud environments where compute instances are ephemeral.
Summary
Consistent hashing is a cornerstone of scalable and fault-tolerant distributed systems. It provides:
- Even distribution of load
- Minimal disruption when servers join or leave
- Support for massive scale and dynamic environments
From NoSQL databases to distributed caches and modern cloud platforms, consistent hashing enables efficient, predictable distribution of work.
메타데이터
- post_id
- ba23fbd35dcc
- slug
- consistent-hashing-in-modern-architectures-ba23fbd35dcc
- url
- https://medium.com/@comatrix/consistent-hashing-in-modern-architectures-ba23fbd35dcc
- canonical_url
- https://medium.com/@comatrix/consistent-hashing-in-modern-architectures-ba23fbd35dcc
- author_url
- https://medium.com/@comatrix
- status
- ok
- fetched_at
- 2026-06-17 19:05:49