Skip to main content
InterviewHubPRO
Section Overview
Q22

Question 22 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

44%
MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

What makes a Good vs Bad Shard Key in MongoDB?

senior LevelDatabases & SQL

In Simple Words: Selecting the right shard key is the most critical architectural decision:

  • Bad Shard Key (Monotonically Increasing _id or timestamp):
    • All new writes route to the single shard owning the highest range.
    • Creates a Hot Shard bottleneck while other shards sit idle.
  • Bad Shard Key (Low Cardinality, e.g. country):
    • Creates massive indivisible chunks that cannot be balanced across shards.
  • Good Shard Key (High Cardinality + High Query Isolation):
    • Compound Shard Key: { tenantId: 1, createdAt: 1 } or Hashed Shard Key ({ _id: "hashed" }).
    • Distributes writes evenly across all shards while allowing targeted queries.