Try
↑ ↓ move↵ openesc close

Curriculum · Module 01, Scaling a Service

Lesson 3 · 7 topics · 36 min · Intermediate · 0/7 done

Consistent hashing

Spread keys over nodes so that adding or removing one node moves only a small share of them.

What each topic covers

  • The simplest way to spread keys over nodes reshuffles almost everything when the cluster changes size.
  • Hash nodes and keys onto the same circle, and let each key belong to the next node clockwise.
  • Add and remove nodes, count the keys that move under the ring and under hash mod N, and sweep virtual nodes.
  • Measured movement and imbalance with and without virtual nodes, and the problems consistent hashing does not solve.
  • Estimate imbalance from the square root of the point count, then see why a bigger cluster needs more points for the same target.
  • Two ways to place keys without a ring: highest score wins, and a precomputed lookup table with near-perfect balance.
  • Three checks on who moves when a node joins, what virtual nodes fix and why a hot key stays hot, plus the papers.

Topics

  1. 1Why hash mod N hurts3 min
  2. 2The ring and virtual nodes4 min
  3. 3Add a node to the ring and to mod N7 min
  4. 4What the ring balances and what it leaves5 min
  5. 5How many virtual nodes is enough7 min
  6. 6Rendezvous hashing and Maglev tables7 min
  7. 7Check ownership, balance and hot keys3 min

Practise this lesson

13 interview questions on consistent hashing, with worked answers and sources.

Practise these

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