Analyze and improve the performance of a sharded MongoDB cluster.
Instruction: Discuss your methodology for analyzing performance bottlenecks in a sharded MongoDB cluster and propose solutions to address these issues.
Updated
Official answer
Map the topology, server versions, shard keys, zones and workload before changing anything. Compare per-shard request rates, tail latency, CPU, I/O, cache eviction, replication lag and data distribution. Separate a query-routing problem from a storage bottleneck or an overloaded router.
Inspect representative query plans through mongos. Determine whether predicates target the intended shards, whether each shard uses appropriate indexes, and whether sorting, joins or aggregation merge work dominates. Balanced bytes do not mean balanced request volume.
Correlate a hot shard with key frequency, monotonic inserts, a large tenant or popular document. Moving ranges may move the hotspot without dividing it. A zone policy can constrain placement and may prevent otherwise useful balancing; review its purpose before changing it.
Choose the smallest evidenced intervention: improve a query/index, reduce avoidable work, add capacity or evaluate a supported resharding plan. Do not tune cache or range sizes blindly or rely on obsolete MMAP-era metrics. Include migration overhead and recovery capacity in the plan.
Measure result correctness, latency, throughput and errors under comparable load after the change. Test skew and failure cases and retain a reversal plan.