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

Range-Based Partitioning

Dividing data into continuous ranges of partition key values, enabling efficient range queries but risking hotspots.

Range-Based Partitioning

What you'll learn: How to divide data across partitions using continuous ranges of key values, and the tradeoffs between efficient range queries and uneven load distribution.


What is Range-Based Partitioning?

Range-based partitioning divides your data by assigning continuous ranges of partition key values to different partitions. Instead of scrambling keys with a hash function, you keep keys in their natural sorted order and split them into segments.

For example, imagine partitioning customer records by last name:

  • Partition 1: A–F
  • Partition 2: G–M
  • Partition 3: N–S
  • Partition 4: T–Z

Each partition stores all records whose key falls within its assigned range.

How It Differs from Hash-Based Partitioning

Unlike hash-based partitioning (which scatters keys randomly), range-based partitioning preserves sort order. This is similar to organizing a library by call numbers: books with similar numbers sit together, making it trivial to retrieve all books in a numeric range.

Benefits

  • Efficient range queries: Fetching all users born between 1990–1995 only touches one or two partitions
  • Natural data locality: Related keys (timestamps, alphabetical names) cluster together
  • Scan operations: Sequential reads are fast because data is ordered

The Hotspot Risk

The major drawback: uneven distribution. If your application creates many records with keys in one range (say, usernames starting with "S"), that partition becomes a bottleneck while others sit idle. Real-world data rarely distributes uniformly across alphabetical or numeric ranges.

Key Takeaway: Range-based partitioning enables powerful range queries by preserving key order, but requires careful partition boundary selection to avoid creating hotspots in heavily-accessed ranges.