Skip to content
StackDecode
System Design
5. Advanced Database ArchitectureAnimated

Range-Based Sharding

Each shard owns a contiguous key range.

The idea

Range queries are cheap because neighbours share a shard.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

123456789101112131415161718192021222324252627282930N1: 8N2: 7N3: 8N4: 7
  • outlined = moved key

Range-based: keys are split into contiguous ranges, one per node. Good for range queries; risky for hot spots such as increasing ids.

nodes:
4
moved:
0
1/2

Each square is a key; its colour is the shard that stores it.

Step by step

  1. 1Split key space into ranges
  2. 2Map ranges to shards
  3. 3Route by range
  4. 4Split hot ranges

Where it is used

Time series and ordered data.

Watch out for

Hot spots when keys increase steadily.

Related