Assigning Records to Shards by a Key

A shard rule chooses a partition for a record. Use the same routing basis for writes and reads under a compatible layout.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a simple partition
  2. Plan queries crossing partitions
  3. Route related writes to the same owner under a fixed scheme
  4. Test skew and migration as different problems

Trace a simple partition

With four shards, an illustrative modulo rule sends ID nine to shard one. Increasing the count can change placement for old IDs, so repartitioning needs a strategy. Modulo arithmetic supplies the rule.

Plan queries crossing partitions

A filter by another field can need results from several shards unless there is a suitable index. See shard routing.[1]

Route related writes to the same owner under a fixed scheme

With three toy shards and assignment by positive ID modulo three, IDs seven and ten both route to shard one. Changing to four shards changes those assignments for many IDs. Routing logic and data movement must agree during a migration. See quotient and remainder.

ID 7: 7 mod 3 = 1
ID 10: 10 mod 3 = 1
With 4 shards: respectively 3 and 2
Routing version changes which owner answers

Test skew and migration as different problems

A stable computed owner does not ensure even load if some keys are much busier. Compare per-shard work and storage. During migration verify reads and writes address the intended versioned owners.

References

  1. Google, Site Reliability Engineering ↩