Lab · Distributed data
Sharding
When one database can't hold all the data or take all the writes, you split rows across shards by a shard key. The key you pick decides whether load is even, which queries stay cheap, and how painful adding a shard will be.
Try it
The lab is busy, so only some requests are drawn as dots, few enough to follow. The numbers still count every request.
- Shard router — hash(user_id) — healthy
- Shard 0 — 23 rows — healthy — 8 writes/s
- Shard 1 — 31 rows — healthy — 10 writes/s
- Shard 2 — 22 rows — healthy — 8 writes/s
- Shard 3 — 24 rows — healthy — 8 writes/s
- Write
- Hot key
Hottest shard vs average
1.2×
Healthy: load is spread
Rows written
100
Reading one user's posts
1shard
how many shards to ask
Search posts by hashtag
4shards
not the shard key → ask all
Rows moved by last resize
—
press "Add shard"
Numbers add up:100 rows across shards = 100 rows writtenThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
Follow a request
Pause to pick a request that is on screen.
Writes per second by shard
The tick marks the average. A bar far past it is a hot shard.
Rows stored by shard
What just happened
Nothing yet. Start traffic or run an experiment.
What this model simplifies
- Only writes are modelled; each shard's load is its writes per second over the last 2 s.
- Resharding is instant here. Real migrations copy data in the background, double-write or redirect during the move, and verify before cutting over.
- Each shard is a single node. In production every shard is also replicated.