Skip to content
WebsiteHosting.com

concept Backend & software

Consistent hashing and virtual-node imbalance

A new token changes ownership for one interval of a hash ring. Follow the keys in that interval to see why moving three keys can shift 12 of 19 requests per window.

Latest recorded source check · P0135

What it means

Consistent hashing limits which keys change owners when a node joins or leaves. Picture a ring with a mark, called a token, for each position owned by a node. Starting at a key's position, go clockwise to the first token at or beyond it. The node that owns that token owns the key. A new token can therefore take over one interval without disturbing the rest of the ring. It might, however, take over the busiest key.

The example starts after hashing. A deterministic hash gives the same key the same position each time when the hash rule stays fixed. Here, ten positions are given rather than calculated. When a key “moves,” its position stays put; what changes is the node responsible for it.

Try it

Simulation: start with the single token layout, the add-C membership event, and scenario evidence provided. Key 45 receives 10 requests per window; each other key receives one. Follow key 45: it used to reach B's token at 80, but now reaches C's new token at 50 first. Three of the ten keys change owners. Together they account for 12 of the 19 requests per window.

Consistent hashing and virtual-node imbalance

Explain minimal key movement and uneven load during node changes

Simulation
Modeled outcome: Ring

Reassign keys to the next clockwise token and separately sum their request weights.

Consistent hashing and virtual-node imbalance: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Ownership and request demand

Moved assignments

  1. Moved keys3
  2. Moved request weight12
A keys4 keys
B keys3 keys
C keys3 keys
A request weight4 requests
B request weight3 requests
C request weight12 requests

The ring uses fixed token and key positions, with clockwise selection including wraparound. Request weight is not a second key. The two measures have different units.

Token positions and key ownership
Before

Tokens: A:20, B:80

After

Tokens: A:20, C:50, B:80

KeyWeightBeforeAfterMoved?
51AANo
151AANo
251BCYes
351BCYes
4510BCYes
551BBNo
651BBNo
751BBNo
851AANo
951AANo

Evaluated inputs

Required scenario evidence
provided
Token layout
single
Membership event
add-C
Requests for key at position 45
10 req/window

Ten fixed illustrative hash positions, explicit token layouts, one hot key. No actual random hash function, replication, unequal node capacity or migration timing. Request weights are stipulated; key count is not measured load.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

Change only Requests for key at position 45 from 10 to 1. The same three keys still change owners, but now they account for just 3 requests per window. Compare the key counts with the request totals: changing a key's popularity affects the second count, not the first. Reset restores the single-token addition with 10 requests for key 45 and evidence provided.

The request input accepts whole numbers from 1 to 100. An invalid input gives no result. With valid inputs but required scenario evidence set to missing, the result is unknown, not zero movement. These are local examples, not measurements of a cluster.

Which keys does C take?

Before the addition, A has a token at 20 and B has one at 80. Inserting C at 50 splits B's interval: positions after 20 through 50 now reach C, while positions after 50 through 80 still reach B. The table follows all ten keys with the original request weights.

Key positionsOwner beforeOwner afterRequests per window for this group
5, 15AA2
25, 35, 45BC12
55, 65, 75BB3
85, 95AA2

The last row illustrates wraparound. From 85 or 95, continue clockwise past the end of the numbered positions. The first token is A at 20, both before and after C joins. A finishes with four keys and four requests per window. B and C finish with three keys each, but B has three requests per window and C has twelve: one for key 25, one for key 35, and ten for key 45.

For a contrasting membership event, start from that same A–B ring and remove B instead of adding C. All six keys that used to reach B now reach A, carrying 15 requests per window. A's original four keys stay with A. A ends up with all 19 requests, but only 15 changed owners. The traffic assigned to a node after an event is not necessarily the traffic that moved there.

What virtual nodes change

A virtual-node layout gives a physical node several token positions, so its share of the ring can consist of several separate intervals. The original Dynamo design used this flexibility to reduce uneven ownership and to assign different numbers of tokens to machines with different capacities. Multiple positions for a node do not mean multiple owners for a key in this example.

In the simulation's virtual layout, A has tokens at 10, 50, and 90; B has tokens at 30, 70, and 99. With membership unchanged and one request per key, each node owns five keys and receives five requests per window. Now consider key 45 again. Its first clockwise token is A at 50. If that key receives ten requests instead of one, all nine additional requests count toward A. The key counts remain five apiece, no keys change owners, and the request totals are now 14 for A and 5 for B.

Keep the single-token layout and the addition of C, but reduce the hot key’s weight from ten to one. The moved key count stays three and the moved request weight becomes three instead of twelve. The position and ownership of key 45 did not change. This distinguishes changing the workload from changing the ring.

In practice

When assessing a membership change, compare owners for the same keys before and after. Count the keys whose owner differs to answer “How much of the mapping changes?” Then sum the requests for those keys over the same window to answer “How much traffic gets a different owner?” To find the busiest resulting node, include its retained keys as well as its newly assigned ones.

This ring has fixed positions, one adjustable request weight, and no replication, unequal node capacities, or migration timing. Its request totals are not measurements of utilization or a basis for changing a live configuration. If key counts look even but traffic does not, the useful next observation is the request count for the busiest key and which node owns it. Stable ownership and even traffic are different goals; a ring can deliver the first without delivering the second.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Why use virtual nodes?

Virtual nodes give one physical machine several ownership intervals on the ring. Dynamo uses this to address uneven placement and different machine capacities. It does not ensure uniform request load: token placement, key popularity and routing still matter.

Can one hot key dominate a well-balanced ring?

Yes. The same key continues to map to one owner in this non-replicated example, so even key counts do not guarantee equal request loads.

Do all keys move when membership changes?

No in the shown successor mapping. Only keys whose next token changes move. Removing a token can redistribute its interval to a surviving successor.

Is this a benchmark of a hash function?

No. The example uses ten predetermined key positions and explicit request weights. Moving three keys can move twelve units of request demand in the same fixture. Neither count measures CPU usage, latency, or a hash function’s distribution on a real workload.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. Consistent Hashing and Random Trees

    consistent hashing. Monotonic mapping moves keys affected by added buckets rather than redistributing all keys; balance is probabilistic under assumptions.

    Checked .

  2. Dynamo: Amazon’s Highly Available Key-value Store

    Section 4.2 (partitioning algorithm). Dynamo §4.2 uses virtual nodes to distribute ownership intervals and account for heterogeneous node capacity. More evenly distributed ownership does not by itself establish equal request rates; the lab stipulates keys and request weights.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.