Data & storage / 9 / 15
Sharding
A chat service's messages table reaches 6 TB and one server can no longer hold it. We split it across shards, choose a shard key, meet a hot shard and a hot key, and add a fourth shard without moving everything.
- 13 min
- Intermediate
- 10 steps
- Query p95
- 1 400 ms
- Hottest shard load
- 98 %
- Shards per query
- 1
- Largest shard
- 6 TB
- request
- reply
- redelivery
- duplicate
- lost
Numbers are a model scenario, not measurements
The real request
Chat API → Messages DBRequest
INSERT INTO messages (chat_id, sender_id, body)1
VALUES ('c_8812', 'u_42', 'see you at 7');
Response
INSERT 0 1
Time: 1380.5 ms2
chat_id— The chat this message belongs to. Almost every query filters on it.Time— 1.4 seconds to insert one message. The server is out of room, not the query.
Build it yourselfCheat sheetCompare lessons
Course: 74 lessons
01 Foundations
02 Scaling
03 Data & storage
04 Communication
05 Reliability
06 Architecture
07 Security
08 Shipping
09 Whole systems
10 Business processes
11 Case studies