Skip to content

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
12CLIENTUsersSERVICEApplicationserversDATABASEMonolithPostgres

Select a component to see what it is responsible for and which state it owns.

  1. 1Users → Application servers: Requests
  2. 2Application servers → Monolith Postgres: Reads and writes until cutover

What you need to know

0 of 2 checks done
  1. 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.

  2. Check

    Sharding by a hash of each row's own ID spreads data perfectly evenly. What happens to 'load this page's blocks'?