Course contentsShow
← System Design
Lesson 1458 of 1,91936. Data Partitioning Strategies in DepthFree lesson

Mapping Keys and Nodes to the Ring

How hash functions map both data keys and server nodes onto the same circular hash space.

Mapping Keys and Nodes to the Ring

What you'll learn: How consistent hashing uses the same hash function to place both data keys and server nodes onto a shared circular hash space.

The Core Mechanic

In consistent hashing, the same hash function maps two different types of things onto the ring:

  1. Data keys (like user IDs, session tokens, cache keys)
  2. Server nodes (your actual machines or instances)

Both occupy positions on the same 0–360° circle (or 0–2³² numeric range).

How It Works

For data keys: Apply the hash function to the key itself.

  • hash("user:12345") → position 87° on the ring

For nodes: Apply the hash function to a node identifier (IP, hostname, UUID).

  • hash("server-node-A") → position 45° on the ring
  • hash("server-node-B") → position 200° on the ring

The assignment rule: Each data key is stored on the first node encountered when moving clockwise from the key's position.

Why Both Share the Same Space

This shared mapping creates the elegant property of consistent hashing: when you add or remove a node, only keys located between that node and its predecessor need to move. The rest stay put because they're still encountering the same "first node clockwise."

Imagine a clock face where both appointment times (keys) and people (nodes) are marked. Each appointment goes to the first person clockwise from its time—simple, deterministic, and minimal disruption when people arrive or leave.

Key Takeaway:
Consistent hashing maps both data keys and server nodes onto the same circular hash space using the same hash function, allowing keys to be assigned to nodes by a simple clockwise-traversal rule.