07 / 15

What are different sharding strategies?

Difficulty: 6/10
range sharding, hashed sharding, zone sharding

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.

Scenario Questions

0-2 years experience

  1. 1We have a collection of user profiles that we want to distribute across three shards. How would you choose between range and hashed sharding for the 'username' field, and what steps would you take to set it up?
  2. 2If you insert documents with sequential IDs into a collection sharded by a range on that ID, what performance issue might you see and why?

2-5 years experience

  1. 1Our application started seeing uneven query latency after we sharded the 'orders' collection by a hashed key. Walk me through how you would investigate and rebalance the shards.
  2. 2We need to support geo‑based routing for a 'stores' collection. Which sharding strategy would you pick, and what trade‑offs does it introduce compared to a simple hashed shard key?

5-8 years experience

  1. 1Design a sharding plan for a high‑write IoT telemetry collection that receives millions of points per minute. Explain which sharding strategy you’d use, how you’d handle hot spots, and how you’d monitor chunk migrations.
  2. 2Our legacy monolithic MongoDB cluster must be split into a sharded cluster without downtime. Describe the migration steps, how you’d choose shard keys, and how you’d mitigate data loss or service interruption.

8+ years experience

  1. 1At a company‑wide level we need to standardize shard key selection across dozens of microservices. How would you create a governance framework that balances performance, operational complexity, and future schema evolution?
  2. 2We are planning to move from a single‑region sharded cluster to a multi‑region, zone‑aware deployment. What architectural changes are required, and how would you evaluate the impact on latency, consistency, and cost?

Follow-up Questions

  • What problems arise if the chosen shard key becomes a write hotspot?
  • How does chunk size influence migration and balancing?
  • When would you prefer zone sharding over range or hashed sharding?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.