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

Clockwise Key Assignment Rule

Keys are assigned to the first node encountered when moving clockwise from the key's position on the ring.

Clockwise Key Assignment Rule

What You'll Learn

You'll learn exactly how a key finds its home node on a consistent hash ring—by traveling clockwise until it meets the first available server.


The Core Idea

In consistent hashing, both keys (data items) and nodes (servers) are mapped to positions on a circular hash ring using the same hash function. Once you've positioned a key on the ring, the clockwise key assignment rule determines which node stores that key: the key is assigned to the first node encountered when moving clockwise from the key's hash position.

Think of it like a circular parking lot where you enter at a specific spot and walk clockwise until you find the first available parking space—that's where you park.


How It Works

  1. Hash the key: Apply your hash function to get a position on the ring (e.g., key "user:42" → position 87)
  2. Start at that position: Locate where 87 sits on the 0–359 ring
  3. Move clockwise: Scan in the clockwise direction
  4. Stop at first node: Assign the key to the first node you encounter

Example

Ring positions:
- Node A at position 50
- Node B at position 150
- Node C at position 280

Key "user:42" hashes to position 87
→ Move clockwise from 87
→ First node encountered: Node B (at 150)
→ Assign "user:42" to Node B

This simple rule ensures deterministic placement—any client performing the same calculation will route the request to the same node, with no need for a central coordinator.


Key Takeaway:
The clockwise key assignment rule provides a deterministic, decentralized method for mapping keys to nodes: always walk clockwise from the key's hash position to the first node on the ring.