Try
↑ ↓ move↵ openesc close

Interview prep / Consistent hashing

Mid · Consistent hashing · System design interview question

For about a minute after a node is added, two application servers disagree about the ring membership. What goes wrong, and how do real systems limit the damage?

Sketch your own answer first, then compare it with the one below.

A strong answer

For keys in the arcs the new node took, the two servers compute different owners. Server A, which has not heard of the node, writes or reads at the old owner. Server B goes to the new node. For a cache, B misses on data that A cached, and A may serve values that B has since updated, so staleness appears. For a data store it is worse, because a write through A can be invisible to a read through B.

Consistent hashing keeps the disagreement small. Only keys in the new node's arcs, about one in N + 1, are affected. With hash mod N the two views would disagree about most keys.

The damage is limited in a few ways:

  • Version the membership. Each change gets an epoch number. Requests carry the sender's epoch, and a node that sees an older one rejects or redirects, so the stale server learns immediately.
  • Spread membership by gossip or from a coordination service, so the window of disagreement is seconds, not minutes.
  • For caches, accept brief misses and rely on TTLs. For stores, do a dual read during the transition: ask the new owner, and fall back to the old one.
  • In a Dynamo-style design, every node knows the whole ring and can forward a request to the right replica.

Sources

Learn it by running it

The consistent hashing lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms