When one database machine cannot hold all the data or serve all the requests, the rows of a table are split across several machines, called shards. Each row goes to one shard according to its shard key. Choosing that key is the big decision: it sets how evenly data and traffic spread, and which queries can be answered by one shard and which must ask them all.
Each dot in a shard is one user record, coloured by country; each shard stands for one database machine. Change the shard key or the number of shards and the records move to their new shards, ringed so you can count them. A shard turns red when it serves well above its share of requests.
Profile, settings and everything else stored per user row.
The storage one database machine can comfortably manage.
Room left for growth before the next split.
1. Total data
2. Shards needed
3. With an evenly spread key (user id)
4. With country as the key
5. A query that does not include the shard key
Step 1 is the storage estimate from the back-of-the-envelope chapter of Alex Xu's System Design Interview, Vol. 1, which also lists sharding, and its hotspot and resharding problems, among the ways to scale a database. Steps 2 to 5 follow directly: a shard can only hold so much, and a row lives on exactly one shard, chosen by its key.
One is the database's own guidance; the other is a company's account of sharding its production Postgres.
continent field as the key, "the shard key would have a cardinality of 7", so "adding more than seven shards would not provide any benefit." On keys that only grow: "all new inserts are routed to the chunk with maxKey as the upper bound", and that shard "becomes the bottleneck for write operations." Queries without the shard key "are broadcast to all shards", which it calls scatter-gather queries.MongoDB's pages are its official manual; Notion's is a first-hand engineering post (Garrett Fidalgo, October 2021). Quoted phrases are short attributed quotations; everything else is described in our words.