advanced25 min studyLesson 327 in Engineering

Consistent hashing and a membership change

Quantify expected key movement under explicit placement assumptions without confusing balance, hotness, or replication.

On this page

What you’ll understand

  • Explain the limited-remapping goal of a consistent placement function.
  • Calculate expected movement for a balanced equal-weight node join.
  • Separate key-count balance from byte and request-rate balance.

Changing a cache cluster's membership can turn placement into an origin-load event. If most keys suddenly map elsewhere, warm entries become unreachable through the new mapping and many requests refill together. Consistent hashing aims to limit remapping when nodes join or leave. Its useful movement claims depend on a specified placement scheme and distribution, not merely on naming a hash function or drawing a ring.

Placement stability is a distinct property

With simple hash-modulo-node-count placement, changing the divisor changes assignments for many keys. A consistent scheme instead tries to preserve assignments among unaffected owners, assigning a joining node a share without arbitrarily reshuffling every existing key. The original ring approach places node positions and key hashes on an ordered space; ownership follows a defined successor rule. Other placement algorithms offer related properties, so specify the actual mapping rather than assuming all distributed key stores use the same ring.

Membership views must also converge. Clients using different node sets can reach different owners even when each computes its mapping correctly. Decide whether requests dual-read, migrate, redirect, or accept temporary misses, and how the transition handles writes. A cache miss after remapping is not necessarily data loss at the authoritative origin, but the refill traffic can still overwhelm it. Separate disposable cached replicas from any state whose relocation requires durable handoff.

E[Kmoved]=Kn+1\mathbb{E}[K_{\rm moved}]=\frac{K}{n+1}
For K uniformly placed keys and a joining equal-weight node expected to own 1/(n+1) of an n+1-node consistent placement, this is expected moved key count. It assumes only that new ownership changes; it is not an exact per-join bound or a byte-traffic prediction.↔ Scroll wide equations horizontally.

Balance has several denominators

A single random ring position can own a surprisingly large interval. Multiple virtual positions per physical node can reduce ownership imbalance, but the degree depends on count, weighting, hash quality, and the workload. Equal numbers of keys still need not mean equal memory if object sizes differ, or equal request rate if one key is very hot. A single hot object cannot be split just by adding virtual nodes unless the application's replication or partitioning protocol changes.

Replication and failover introduce additional owners and movement rules. Distinct virtual positions do not imply distinct physical failure domains. During a join, controlled warming or migration may preserve useful residency but consumes network and memory capacity. Pace that work and measure the actual moved bytes, origin requests, and overloaded owners. A theoretical expected fraction can look small while a skewed group of moved keys causes a large traffic spike.

Dmoved=∑i∈Msi,Qj=∑i:owner⁡(i)=jqiD_{\rm moved}=\sum_{i\in\mathcal M}s_i,\qquad Q_j=\sum_{i:\operatorname{owner}(i)=j}q_i
M is the moved-key set, si is stored bytes per key, and qi is requests/s. D is bytes and Qj is a node's offered request rate. Key-count balance alone constrains neither quantity when sizes or popularity are skewed.↔ Scroll wide equations horizontally.

Predict an assumption, then verify real membership

Before adding capacity, record the current mapping, residency, owner load, and origin headroom. Compare expected movement with actual keys and bytes remapped in a staging trace or controlled rollout. Include retries and negative entries in the workload. Test a node failure separately from a planned join: absent old data and abrupt membership changes can create a different refill shape. A successful normal join does not establish correct degraded reads under inconsistent client views.

The probability lab represents a deliberately balanced fixed new-node share, not a hash-ring implementation. Reset and set both p=0.2, n=20, predict four sampled keys assigned to a new one-fifth share on average, then inspect. The trials assume independent uniform keys given that fixed share. A random single-position ring can have a variable share and correlated unconditional assignments, so its distribution need not be this binomial. Play highlights outcomes rather than moving actual keys; use the distinction to state the missing placement assumptions.

A fifth equal-weight owner

An ideal balanced consistent placement has 100,000 uniformly distributed equal-size keys on four nodes. A fifth equal-weight node joins and takes its one-fifth share without remapping keys among old nodes.

  1. Expected moved keys are 100,000/5=20,000. Under the explicitly balanced share this is 20% of the key space; a real random placement may differ.

  2. For comparison, uniform hash values with modulo four changing to modulo five retain the same numeric owner for one fifth of residues over a complete twenty-residue period. That remaps 80%, or 80,000 expected keys under the stated uniform model.

  3. Neither count establishes origin load. If moved keys are unusually hot or large, the refill request rate and bytes can be disproportionate. Membership synchronization and paced warming determine whether the expected movement is operationally affordable.

The result

Limited key remapping can protect warm residency, but balance and transition capacity still require measurements at the correct units.

Explore the model

Interactive lab

Interactive lab · probability

A fixed one-fifth ownership share

Reset, set p=0.2, n=20;predict mean 4 keys in a fixed balanced new-node share. The iid binomial model is not a consistent-hash ring, membership protocol, or migration simulator; a random owner's variable interval changes its assumptions.

A fixed one-fifth ownership shareThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forExpected key movement does not automatically describe bytes, popularity, or a particular random ring's outcome.

Check your understanding

Why can moving 20% of keys produce much more than 20% of refill traffic?

Try it yourself

Under the same ideal equal-weight assumptions, a nine-node cache adds a tenth owner with two million uniformly placed keys. Estimate moved keys. If those keys average 4 KiB, estimate their payload, keeping it separate from all transfer overhead.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The joining share is one tenth, then multiply moved count by 4,096 bytes.

Compare with the solution

Expected movement is 2,000,000/10=200,000 keys. Their expected payload at the declared average is 819,200,000 bytes, or 781.25 MiB. This excludes protocol bytes, duplicate fetches, metadata, and demand skew. The calculation assumes the stated average applies to the moved population rather than inferring it from the cluster-wide average without evidence.

Take it with you

  • Consistent placement limits remapping under a specified membership rule.
  • The 1/(n+1) join fraction needs equal-weight uniform/balanced assumptions.
  • Key count, moved bytes, owner QPS, and failure-domain diversity are different budgets.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.