FUNDAMENTALS & NETWORKING · SUBTOPIC
Modulo Hashing vs. Consistent Hashing
See why hash % N causes massive cache misses during scaling and how the ring moves only 1/N keys.
IntermediatePart of Consistent Hashing
Subtopics in Consistent Hashing (2)
In plain words
With modulo, adding one shelf makes you re-sort almost every book in the library. With a hash ring, you only slide a small slice of books onto the new shelf.
Think of it like…
Re-seating an entire stadium whenever one person arrives vs. letting one row shift slightly.
Loading interactive diagram
Loading interactive exercise
Theory & how it works
The exact math of key movement
With N nodes, adding 1 node in consistent hashing moves approximately K / (N + 1) keys on average (where K is total keys). With 10 nodes, adding an 11th node moves only ~9% of keys instead of ~91% under modulo.
Key points & practical guide
Summary checklist
- Modulo (
% N) remaps nearly everything on cluster resize - Consistent hashing moves only
~1/Nkeys - Lookup takes
O(log V)with binary search over sorted ring positions
When to use it
- Distributed caches (Memcached/Redis)
- Partitioned NoSQL stores (Cassandra, DynamoDB)
- Stateful routing / sticky edge routing
Watch out for
- Hot keys (celebrities) still hit one node regardless of ring balance - replicate hot keys separately
Quick check
Loading quiz