Skip to content

Partitioning & Sharding

When the data or the writes outgrow one machine, the data has to be split across several, and every key needs a rule that says where it lives. That rule decides which queries stay cheap, how evenly the work is shared, and how much has to move when you add a machine. This module is about choosing the rule, and about what happens when the traffic does not follow it.

You will work with a live sharding lab on ten thousand keys, a sorting exercise, a quiz and a C# example of a hash ring, and every lesson has a moment where you add a shard, send traffic to the wrong place or run a query that has to ask everyone.

  1. Partition strategies: range, hash and directory (18 min). Why data is split, three ways to decide where a key lives, and what each one costs when the shards change.
  2. Choosing a shard key (18 min). The four questions to ask of a candidate key, and the difference between a burst of neighbouring keys and one key that is too popular.
  3. Consistent hashing and virtual nodes (22 min). Why hash mod N moves most keys when a shard is added, how a ring moves only the keys the new shard takes, and what virtual nodes change.
  4. Hot shards and rebalancing (20 min). What rebalancing can move, what it costs, and the floor that a single hot key sets.
  5. Cross-shard queries (16 min). Targeted and scatter-gather queries, what the fan-out costs in capacity and tail latency, and how to avoid it.
  6. Recap and quiz (12 min). The module in one page, a design checklist, and a quiz.
  • Choose between range, hash and directory placement for an access pattern, and say what each costs.
  • Judge a shard key by its number of values, its most frequent value, its growth and the queries it serves.
  • Work out how many keys move when a shard is added, for hash mod N and for a ring, and what virtual nodes change.
  • Recognise a hot shard, say whether rebalancing can fix it, and say what to do when it cannot.
  • Spot the queries that scatter to every shard, and name a way to avoid each.

All the numbers in the labs are illustrative. They are for comparing choices, not for forecasting any real product.

Built by GhaziAlibi.

© ShardCraft. All rights reserved.