AlgoViz

Partitioning strategies

medium 25 min

Range, hash and list partitioning are three rules for placing rows.

Where it shows up

The same pattern appears across everyday software.

  • Redis Cluster: hash to fixed slots

    CRC16 of the key, modulo 16,384 slots. Slots move between nodes, keys keep their slot.

  • MongoDB: range or hash

    A collection can be sharded by ranges of the key or by its hash. Zones add list-like placement, for example by data centre.

  • CockroachDB: ranges that split

    Data is one sorted key space cut into ranges that split when they reach the default size. Hash-sharded indexes spread keys that only grow.

  • PostgreSQL: all three

    Declarative partitioning supports range, list and hash, sub-partitions, and a default partition.

  • Spanner: advice on keys

    The documentation warns against a first key part that only increases for tables with many writes, and recommends random UUID version 4 values among other methods.

  • Elasticsearch: modulo on purpose

    A document's shard is a hash of its routing value modulo the number of primary shards, which is why that number is chosen with care.