← Lessons

quiz vs the machine

Gold1400

Databases

Range Based Sharding

Split data by ordered key ranges to keep scans fast but watch for hotspots.

5 min read · core · beat Gold to climb

Sharding by Order

Instead of hashing keys, range based sharding assigns contiguous spans of the key space to shards. Keys from one letter or one time window live together. Systems like HBase and many key value stores use this approach.

The Big Advantage

Because ordered keys stay together, a range scan touches only the shards covering that span. Listing all orders from a single day or all users whose name starts with a letter reads from a small set of shards rather than the whole cluster.

The Big Risk

If writes cluster at the end of the key space, such as a timestamp or an auto incrementing id, all new writes land on one shard. This hotspot overwhelms a single node while others sit idle. The same happens for popular ranges on reads.

Splitting and Merging

Ranges are split when a shard grows too large and merged when shards shrink. A coordinator tracks range boundaries so requests route to the right shard.

Key idea

Range sharding keeps ordered keys together so scans are efficient, but sequential write patterns can pile onto one shard and create a hotspot.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main benefit of range based sharding?

2. Why can a monotonically increasing key cause a hotspot?

3. What happens when a range shard grows too large?