shard key selection, data distribution, migration strategy
Every shared collection has a shard key.
1
connect to a mongos instance and run the db.printShardingStatus() method
2
connect to a mongos instance and run the sh.status()
Scenario Questions
0-2 years experience
1We have a collection of user activity logs that we need to shard. How would you choose a shard key for this collection?
2If you pick `userId` as the shard key and notice most queries filter only by `timestamp`, what impact does that have on performance?
3Given a small dataset, how would you verify that your chosen shard key is providing balanced chunks?
2-5 years experience
1Our service is experiencing hot spots after sharding the orders collection on `orderId`. Walk me through how you'd diagnose the issue and what alternative shard key you might consider.
2During a rollout we added a compound shard key (`region`, `customerId`). Some queries are now slower. Explain why and how you'd decide whether to keep or change it.
3We need to add a new field to the shard key for future growth. What steps and risks are involved in re‑sharding an existing collection?
5-8 years experience
1Design a migration plan to change the shard key of a high‑traffic collection from `userId` to a compound key (`userId`, `createdAt`) without downtime. What are the key challenges?
2Explain how the choice of shard key affects balancing, chunk migrations, and read/write latency at scale, and how you would monitor and adjust it over time.
3If you must support both range queries on `date` and equality queries on `category`, how would you evaluate trade‑offs in selecting a shard key or using hashed vs ranged sharding?
8+ years experience
1Our platform spans multiple data centers and we need to shard across them. How would you architect a global sharding strategy, including shard key selection, to minimize cross‑region traffic and support future schema changes?
2When legacy collections have suboptimal shard keys, what governance process would you establish to prioritize re‑sharding, and how would you balance engineering effort versus performance gains?
3Discuss the long‑term implications of choosing a hashed shard key versus a compound ranged key for a multi‑tenant SaaS product, considering tenant isolation, scaling, and operational complexity.
Follow-up Questions
What metrics would you set up to know the shard key is working well?
How would you handle a situation where the chosen key becomes a hotspot after traffic changes?
Can you describe a rollback plan if the new shard key causes performance regression?
Sharethis question
Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.