Replication and sharding solve different problems. Replication copies all the data to every member of a set. Sharding does the opposite: it partitions the data across groups, each group itself a replica set, called a shard, so that the whole dataset and the whole write load exceed what one group must hold. Queries are routed by a shard key, a field or small set of fields whose value decides which shard owns each document.
That makes sharding the largest structural decision in a MongoDB system's life. Two judgments govern it: when to shard at all, and how to choose the key — among the hardest decisions in the system to reverse.
Shard when a named pressure forces it, not before
Sharding is not a compliment you pay a growing system. It is a cost you accept when a named pressure forces it, and the legitimate pressures are few.
First, data volume can grow beyond what one replica set should hold and keep within memory's reach; working-set arithmetic is how you know that point has arrived. Second, write throughput can exceed one primary's capacity. Third, a hard geographic or regulatory placement requirement can demand that data live in particular places.
"We might be big one day" is not on that list. A sharded cluster multiplies operational surface: more members, a routing layer, distributed failure modes, and queries that can scatter to every shard. Paying that multiplication before a pressure is real buys complexity with the budget that should have bought modeling and indexes.
The key must pass three tests, in tension
A good shard key is found by scoring candidates against the workload, on three tests that pull against each other.
First, cardinality: the key must have enough distinct values to divide the data finely. A key with few values can make only a few coarse piles, and it can never balance beyond the number of values it has.
Second, distribution: writes and reads should spread evenly rather than hammering one shard. A key whose values arrive in ever-increasing order, such as a timestamp or a rising sequence, routes all new writes to the single shard holding the current end of the range. Its cardinality may be excellent, and it still produces the notorious hot-shard pattern.
Third, query alignment: the hot queries should carry the key, so the router can send each query to the one shard that can answer it. A hot query without the key becomes a scatter-gather to every shard, every time — the sharded system's version of a full scan. This test decides the user-visible outcome, because a cluster is slowest exactly where the business looks at it most when its common queries cannot be routed.
Each candidate is scored on all three with the workload's real figures, and the winner is the candidate whose weakest test is still acceptable.
Run the arithmetic before choosing
Consider Cedarvale, weighing how to shard its orders across four shards. Shard on customer reference, and the figures are encouraging: 1,200,000 orders divide evenly as 1,200,000 ÷ 4 = 300,000 orders per shard. Customers are numerous — 500,000 of them — so cardinality is excellent, and balance is achieved provided no single customer dominates.
Now shard on store instead. Cedarvale has 14 stores, so the key can make at most 14 piles. Worse, one flagship store takes 60% of orders, so that pile holds 0.60 × 1,200,000 = 720,000 orders on one shard, against 480,000 spread across the shards holding the other thirteen stores. That is a permanent hot spot no rebalancing can cure, because the key itself cannot split one store's value.
A key on order timestamp fails differently: its values are finely divided, but 100% of today's writes aim at today's shard. Fine cardinality, failed distribution.
The customer key has its own weakness: store-based dispatch queries do not carry a customer reference, so they would scatter. The mature answer is often a compound key — store, then customer reference — which lets store queries route to a bounded set and customer queries route precisely, trading a little distribution purity for alignment with the two hot patterns.
The obvious key is the trap
The common shortcut says: shard on the identifier. It is unique, it is evenly spread, and every system has one, so the decision makes itself.
A bare identifier often does pass cardinality and distribution beautifully. It fails the test that decides what users experience: alignment. If the hot queries do not carry the identifier — and dispatch boards, store views, and regional reports usually do not — every one of them scatters to every shard. Uniqueness is a property of a value. A shard key is a property of a workload. The decision makes itself only for teams who have not listed their hot queries, which is to say it does not make itself at all.
Changing a shard key on a large live collection is priced like a migration, never like a configuration tweak — which is why the choosing deserves more care than it usually gets.
Two operating facts complete the picture
First, the balancer moves chunks, not miracles. The cluster continuously rebalances ranges across shards, which smooths accidents of growth. It cannot fix a key whose values themselves concentrate load, as the flagship store showed: no movement of chunks splits a single value.
Second, unsharded collections and scatter queries have known costs, not mysterious ones. Small reference collections can live unsharded and be read by all. Cross-cutting reports can run as scheduled scatter work at quiet hours, where their cost is planned rather than suffered at peak time.
Sharding, judged this way, is modeling at cluster scale: know the operations, count their costs, draw the boundary where the counting says, and treat it as the long-lived commitment it is.
Experience it, don’t just read about it
A shard key is a property of the workload, not of the value is Concept 13 of MongoDB in Practice (Course No. 569), from Cognosco Learning, a learning company powered by AI. The course builds MongoDB design beyond this distinction — Replica Sets — Copies, Elections and Read Preferences, The Working Set — Memory, Storage and the Data You Actually Touch, and Index Judgment in Depth — Coverage, Selectivity and Index Housekeeping — each worked through with an Agentic Socratic AI coach, one learner at a time. Try a Free Preview at cognoscolearning.com.
Navigate your own course.
© 2026 Cognosco Learning. All rights reserved.