ProgramGuru

Consistent Hashing and Data Placement

Change the server list without moving everything

Follow the responsibility

KeyMapped to a stable hash position
Membership mapDefines server positions
OwnerNext server clockwise
ChangeOnly affected ownership ranges move
Key: Mapped to a stable hash position → Membership map: Defines server positions → Owner: Next server clockwise → Change: Only affected ownership ranges move

A distributed cache needs a repeatable way to decide which server holds a key. A simple hash remainder can spread keys, but changing the number of servers can change many assignments. Consistent hashing is a placement technique intended to limit movement when membership changes.

It chooses an owner; it does not make a key durable, replicate it or keep two writers consistent. Those responsibilities need separate mechanisms.

What you’ll learn

  • Compare remainder placement with a hash ring.
  • Explain virtual nodes and membership changes.
  • Recognise hot-key limits that placement cannot solve.

Place keys and servers on the same circle

Imagine a circle of positions. Hash each server identity and key onto the circle. Assign a key to the next server clockwise, wrapping to the beginning when needed. Adding a server takes over the interval just before that server instead of redefining the whole circle.

Real systems often give each server several positions called virtual nodes. This can improve distribution and allow weighting by capacity. The quality of the hash and the number of positions matter; a tiny diagram is not a prediction of production balance.

Add a server and count changed owners

Observe the membership change

Clockwise →Twelve positions
APosition 0
BPosition 4
CPosition 8
DNot joined · 10
Keys with changed owners0 / 12
Key 0A
Key 1B
Key 2B
Key 3B
Key 4B
Key 5C
Key 6C
Key 7C
Key 8C
Key 9A
Key 10A
Key 11A

Three servers own twelve keys. Add D to compare old and new assignments.

Ring positions: A = 0, B = 4, C = 8, optional D = 10. This fixed example omits data migration and virtual nodes.

Initially A, B and C own twelve fixed keys. Adding D lets you compare how many assignments change.

Compare twelve fixed key hashes, 0 through 11. Remainder mode uses hash modulo server count. Ring mode uses a twelve-position circle with A at 0, B at 4, C at 8 and optional D at 10; the next clockwise server owns the key.

Turn on D and compare each key’s old and new owner. The positions are deliberately small and chosen for explanation. Real hashes use a much larger space and usually virtual nodes; this example does not model migration or cache recovery.

All participants need a usable membership view

If two clients use different server lists, they can send the same key to different owners. Publish membership changes deliberately and define how old and new owners coexist during migration. Database resharding needs data transfer, write routing and verification; updating a ring alone does not migrate records.

A cache may refill missing values from authoritative storage, but simultaneous misses can overload that source. Pace warming and keep rollback information. A single extremely popular key can still overload its one owner; replication, request coalescing or a different access pattern may be needed.

Compare ring placement with explicit partitions

Some systems assign fixed partitions to servers through a directory. Redis Cluster, for example, uses hash slots rather than this exact next-clockwise-server model. Rendezvous hashing ranks servers per key and is another placement approach. Compare membership coordination, weighting and migration before choosing.

Use Redis Cluster’s specification for its actual slot and migration behaviour. Throughput still depends on value size, command cost, hit rate and hot keys; a placement algorithm has no universal requests-per-second rating.

Check your reasoning

What problem does consistent hashing primarily address?
Choose one answer. You can try again.

Answer and explanation

Limiting changed key ownership when server membership changes.

It is a placement strategy.

Check your reasoning

You update a database’s ring. Have its records automatically moved safely?
Choose one answer. You can try again.

Answer and explanation

No; transfer, write routing and validation are still required.

Ownership metadata alone does not move durable records.

Bring the decisions together

Use placement to reduce movement, then design the transition and hot-key path. Continue with sharding for the broader data migration problem.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Sharding and Partitioning in System Design →