Q42: Compare Range-Based Sharding vs Hashed Sharding.

  • Range-Based Sharding: Partitions data into contiguous ranges based on shard key values. Efficient for range queries ($gte, $lte), but risks write hotspots if keys increase monotonically.
  • Hashed Sharding: Computes an MD5 hash of the key to distribute documents uniformly across shards. Excellent for write distribution, but range queries must scatter-gather across all shards.
Key Takeaways
  • Range-Based = Fast range queries, hotspot risk.
  • Hashed = Uniform write distribution, scatter-gather range queries.
Knowledge Check

What is the primary benefit of Hashed Sharding over Range-Based Sharding?