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.
- 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
- 1Split key space into ranges
- 2Map ranges to shards
- 3Route by range
- 4Split hot ranges
Where it is used
Time series and ordered data.
Watch out for
Hot spots when keys increase steadily.