Shard a Live Database Without Downtime, stage 2 of 9: decide
Choose the shard key
Most queries load a page's blocks, a workspace's sidebar or a page's comments. A workspace may have one member or thousands.
System so far· 3 parts
Select a component to see what it is responsible for and which state it owns.
- 1Users → Application servers: Requests
- 2Application servers → Monolith Postgres: Reads and writes until cutover
What you need to know
0 of 2 checks done
The shard key decides which shard each row lives on. Choose it from the queries: the common query should hit one shard, and rows that are joined together should live together.
An even spread is worth little if the common query has to visit every shard.
Check
Sharding by a hash of each row's own ID spreads data perfectly evenly. What happens to 'load this page's blocks'?Think first
Blocks, pages and comments are all sharded by workspace ID. Why does it matter that they share the same key?