07 / 15

What are different sharding strategies?

MongoDB supports two sharding strategies for distributing data across sharded clusters.

Hashed Sharding:
  1. 1

    Hashed sharding uses either a single field hashed index or a compound hashed index as the shard key to partition data across your sharded cluster.

  2. 2

    Hashed Sharding involves computing a hash of the shard key field's value. Each chunk is then assigned a range based on the hashed shard key values.

  3. 3

    Hashed sharding provides a more even data distribution across the sharded cluster at the cost of reducing Targeted Operations vs. Broadcast Operations.

  4. 4

    Post-hash, documents with 'close' shard key values are unlikely to be on the same chunk or shard - the mongos is more likely to perform Broadcast Operations to fulfill a given ranged query.

Ranged Sharding:
  1. 1

    Range-based sharding involves dividing data into contiguous ranges determined by the shard key values.

  2. 2

    Each chunk is then assigned a range based on the shard key values.

  3. 3

    In this model, documents with 'close' shard key values are likely to be in the same chunk or shard.