← Lessons

quiz vs the machine

Gold1340

Databases

Range Based Sharding In SQL

Splitting by key ranges to keep scans fast and rebalance hot spots.

4 min read · core · beat Gold to climb

Splitting By Order

Range sharding divides a table by contiguous spans of the primary key. Keys from A to M live on one shard, N to Z on another. Because keys stay in order, range queries touch few shards.

Strengths

  • Range scans like a date interval read only the shards that cover that interval.
  • Shards can split and merge automatically as data grows or shrinks.
  • Ordered iteration and pagination are efficient.

The Hot Spot Risk

If new rows always have an increasing key, such as a timestamp or auto increment id, every insert lands on the last shard. That shard becomes a write hot spot while others sit idle. Mitigations include hashing a prefix of the key or splitting the busy range so its halves move to different nodes.

Key idea

Range sharding keeps keys ordered so scans stay cheap and shards rebalance by splitting, but monotonically increasing keys create write hot spots.

Check yourself

Answer to earn rating on the learn ladder.

1. Why are range scans efficient with range sharding?

2. What problem do monotonically increasing keys cause?