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

The Hash Ring Concept

Understanding the hash ring as a circular address space where both nodes and keys are mapped to positions.

The Hash Ring Concept

What you'll learn: How the hash ring provides a circular address space for mapping both data and nodes in distributed partitioning schemes.

What Is a Hash Ring?

A hash ring is a conceptual circle (typically representing the range 0 to 2^n - 1) where both your data keys and your server nodes are mapped to positions using a hash function. Instead of thinking of hash values as a linear number line, imagine them wrapping around into a continuous loop.

Here's why this matters: when you add or remove a server, only a small portion of keys need to move—those "adjacent" to the changed node on the ring. This is far better than traditional hash-based partitioning (server = hash(key) % N), where changing N causes massive data reshuffling.

How It Works

Picture a clock face. You hash each server name (e.g., "Server-A") to get a position on the ring—say 3 o'clock. You also hash each data key (e.g., "user:12345") to another position—say 5 o'clock. The key is stored on the first server encountered when moving clockwise from the key's position.

If Server-A is at 3 o'clock and Server-B is at 8 o'clock, any key hashing between 3 and 8 o'clock goes to Server-B. Keys between 8 o'clock and 3 o'clock (wrapping around midnight) go to Server-A.

When you add Server-C at 6 o'clock, only keys between 3 and 6 o'clock move from Server-B to Server-C. The rest stay put.

Why This Beats Simple Modulo

Traditional modulo (hash(key) % server_count) requires rehashing nearly all data when you add/remove servers. The hash ring minimizes this disruption—on average, only K/N keys move when changing N nodes out of K total keys.

Key Takeaway: The hash ring transforms partitioning into a circular address space where adding/removing nodes causes minimal, localized data movement rather than global reshuffling.