Course contentsShow
← Computer Science
Lesson 2686 of 2,87260. Distributed Data and CommunicationFree lesson

Range-Based Partitioning

Distributing data by dividing the key space into continuous ranges assigned to shards.

Range-Based Partitioning

What you'll learn: How to distribute data across shards by assigning continuous ranges of key values to different nodes.

The Core Idea

Range-based partitioning divides your data's key space into continuous segments, where each segment (range) is handled by a specific shard. Think of it like organizing a library: books A-F go on shelf 1, G-M on shelf 2, and N-Z on shelf 3. Each shelf (shard) owns a slice of the alphabet (key space).

Instead of using a hash function to scatter data unpredictably, you define explicit boundaries. For example:

  • Shard 1: user IDs 1–10,000
  • Shard 2: user IDs 10,001–20,000
  • Shard 3: user IDs 20,001–30,000

How It Works

When inserting or querying data, you examine the partition key and determine which range it falls into. If you're looking up user 15,000, you know to query Shard 2 directly. This makes range queries incredibly efficient—finding all users between 10,500 and 11,500 hits only one shard.

Key Characteristics

Advantages:

  • Excellent for range queries (e.g., "all orders from January to March")
  • Keys within a range stay together, enabling efficient scans
  • Intuitive to reason about data location

Challenges:

  • Hot spots: If new data clusters in one range (e.g., timestamps always increasing), one shard gets overwhelmed
  • Requires careful boundary selection to balance load
  • Rebalancing means moving ranges between shards, which can be complex

Practical Example

A time-series database might partition log entries by timestamp ranges. Yesterday's logs go to Shard A, today's to Shard B. Recent queries hit the current shard, while historical analysis can target older shards directly.

Key Takeaway: Range-based partitioning organizes data by dividing the key space into continuous intervals, making range queries efficient but requiring careful management to avoid uneven load distribution (hot spots).