What considerations should be made when sharding a MongoDB database?
Instruction: Discuss the factors and considerations important when implementing sharding in MongoDB.
Updated
Official answer
Start by confirming that sharding addresses the measured capacity or throughput limit. Plan the full topology, including replica-set shards, config servers, routers, network capacity, backups and operational ownership.
Evaluate shard-key cardinality, frequency, monotonicity and query targeting. High cardinality alone does not prevent a hot value or expensive scatter/gather query. Compare ranged and hashed strategies against both reads and writes, and test realistic skew.
The key is not permanently immutable: supported versions can reshard a collection, and refining the key is a separate operation. These are migrations with restrictions and costs. Changing individual shard-key values also has rules; it is not the same as moving whole ranges.
Multi-document transactions can span shards on supported deployments, with extra coordination and performance costs. Review unique-index restrictions, joins, transaction patterns and administrative operations against the exact version rather than assuming all single-server behavior transfers unchanged.
Monitor data distribution, request load, migration traffic and tail latency. Balanced bytes do not imply balanced work. Rehearse failures and restores, preserve capacity headroom and define rollout/recovery criteria before changing the production layout.