# Added one cache server, lost 80% of the cache: Consistent hashing (Mock Interview Notes)

> How to answer the consistent hashing interview question: why hash(key) % N moves 80% of keys when you go from 4 to 5 servers, the worked 0 to 19 key table, the...

Canonical: https://www.internhack.in/notes/consistent-hashing-interview
Last updated: 2026-11-06

By InternHack Team · 2026-11-06 · 13 min read · Interview Prep

The interview question: **"You have 4 cache servers. A key's server is decided by `hash(key) % 4`. A sale is coming, so you add a 5th server. Immediately the load on the database goes up 10 times and the site slows down. Why? And how will you fix it?"**

Adding a server should make things faster. Here it makes them worse, and the reason is one innocent-looking line of code. (To be clear: the sale in this question is an example. We found no documented Indian sale-day incident caused by this. The one real, sourced case is Reddit in 2010, covered below.)

In these notes: the weak answer, the worked math with a 0 to 19 key table, why moved keys become a database stampede, the hash ring, virtual nodes, the answer to the reel's quiz, follow-up questions on jump hash, rendezvous hashing, bounded loads and hot keys, and a ready interview answer.

Status labels from our research: facts from official papers and docs are stated plainly; **[S]** means secondary source only; **[U]** means unverified, our own arithmetic or simulation.

## The weak answer: "We'll just change it to % 5"

A typical first answer: *"Sir, the 5th server will add a little load, it'll warm up. Or we'll just change it to `% 5`."*

The interviewer's push-back: **"With `% 5`, which server will you look for user 7's data on? Before, it was server 3. Now it's server 2. Out of 100 users, how many users' data is now in the wrong place?"**

The answer is **80**. That's the whole problem. With `hash(key) % N`, changing N changes the server for almost every key. nginx's own docs say it plainly: with plain `hash`, "adding or removing a server from the group may result in remapping most of the keys to different servers."

Think of delivery boys. The area office rule: "parcel number % 4 = delivery boy". Each boy knows his houses by heart (that's the cache, warm). A 5th boy joins, the rule becomes % 5, and now 80% of parcels go to a boy who has never been to that house. Every boy calls the office for the address (the database), and the office phone line jams.

## Sign up free to unlock the full notes

The rest of these notes needs a free InternHack account:

- The math: why 80% of keys move
- Why moved keys melt the database
- The fix: put servers on a ring
- Twist: the ring is lumpy, so add virtual nodes
- Who uses it
- The reel's quiz: 10 to 11 servers, how many keys move?
- Follow-up questions and model answers
- Common mistakes
- How to answer this in an interview

Sign up free: https://www.internhack.in/register?from=%2Fnotes%2Fconsistent-hashing-interview

## Sources

- Amazon Dynamo paper, DeCandia et al., SOSP 2007: https://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf
- Jump consistent hash, Lamping and Veach, arXiv 1406.2294 (2014): https://arxiv.org/abs/1406.2294
- nginx upstream `hash` directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#hash
- ketama, Richard Jones (Last.fm, 10 Apr 2007): https://www.metabrew.com/article/libketama-consistent-hashing-algo-memcached-clients
- Cassandra 4.0 cassandra.yaml (`num_tokens`): https://cassandra.apache.org/doc/4.0/cassandra/configuration/cass_yaml_file.html
- Cassandra 4.0 production recommendations: https://cassandra.apache.org/doc/4.0/getting_started/production.html
- Discord, "How Discord Scaled Elixir to 5,000,000 Concurrent Users" (6 Jul 2017): https://discord.com/blog/how-discord-scaled-elixir-to-5-000-000-concurrent-users
- Google Research, "Consistent Hashing with Bounded Loads" (3 Apr 2017): https://research.google/blog/consistent-hashing-with-bounded-loads/
- Karger et al., STOC 1997 (bibliographic): https://researchr.org/publication/KargerLLPLL97
- Mike Perham, "Consistent Hashing in memcache-client" (2009): https://mikeperham.com/2009/01/14/consistent-hashing-in-memcache-client
- The Last Pickle, impacts of changing the number of vnodes (29 Jan 2021): https://thelastpickle.com/blog/2021/01/29/impacts-of-changing-the-number-of-vnodes.html
- HN thread, "Reddit explains their architecture, scaling and recent downtime" (1 Mar 2010): https://news.ycombinator.com/item?id=1159783
- Simon Willison on Reddit's move to Cassandra (13 Mar 2010): https://simonwillison.net/2010/Mar/13/cassandra/
- Facebook, "Scaling Memcache at Facebook", NSDI 2013: https://www.usenix.org/node/172909
- Wikipedia, Akamai Technologies: https://en.wikipedia.org/wiki/Akamai_Technologies
- Wikipedia, Rendezvous hashing: https://en.wikipedia.org/wiki/Rendezvous_hashing
- Hello Interview, consistent hashing deep dive: https://www.hellointerview.com/learn/system-design/deep-dives/consistent-hashing
- PracHub, consistent hashing: https://prachub.com/concepts/consistent-hashing

The key-movement percentages, the 16x DB load estimate and the virtual-node load tables are our own arithmetic and simulations, not published figures. The Reddit 2010 quote comes via an HN commenter (the original post is offline). No Indian sale-day incident caused by modulo sharding was found.

## Related

- [Home](https://www.internhack.in/)
- [Notes](https://www.internhack.in/notes)
