Quick revision
The short answer
Before sharding, we find out what is actually growing: data that can be archived or tiered, a domain or tenant that can move to its own cluster, or a working set that a bigger machine can hold for a few more years. Sharding is the right answer when one logical dataset genuinely outgrows the largest sensible replica set and its queries can follow a good shard key, and then we invest in shard key analysis, skilled operations and rehearsed resharding.
What to remember
In this answer, we saw that sharding spreads one collection across several replica sets behind mongos, and that it brings lasting costs: more operations, limits on queries without the shard key, and a shard key that is hard to change. Before choosing it, we find out what is growing, archive or tier cold data, split unrelated domains or big tenants into their own clusters, and compare the cost curve of scaling up with the engineering cost of sharding. If we do shard, we choose the key from real query patterns, use a managed service or experienced operators, and rehearse resharding and recovery.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Before sharding, we find out what is actually growing: data that can be archived or tiered, a domain or tenant that can move to its own cluster, or a working set that a bigger machine can hold for a few more years. Sharding is the right answer when one logical dataset genuinely outgrows the largest sensible replica set and its queries can follow a good shard key, and then we invest in shard key analysis, skilled operations and rehearsed resharding.
Why this question is asked
An 80 percent growth rate means the data almost doubles every year, so a 2 TB cluster is about 10 TB in under three years. That number creates pressure to act, and sharding is the option everybody has heard of. Interviewers ask this at a senior level because the choice is mostly irreversible in practice: a shard key shapes every query for years, and a wrong decision is paid for by every team that touches the data. They want to see whether we treat sharding as one option among several, compare costs honestly, and set up the work so it succeeds if we do choose it. In this answer, we will recap what sharding involves, look at where the growth comes from, compare the four options with their costs, and then see what a well-run sharding project needs.
1A Quick Recap of What Sharding Means in MongoDB
A MongoDB replica set is a group of servers holding copies of the same data: one primary takes writes and the secondaries follow it. Every member holds the whole dataset, so a replica set grows by buying bigger machines. Sharding splits one collection across several replica sets, called shards. A router process, mongos, sits in front of them and sends each query to the shards that hold the matching data, using metadata kept by the config servers.
The split is decided by the shard key, a field or set of fields present in every document. MongoDB divides the key's range into chunks and spreads the chunks across shards. A query that includes the shard key can go to one shard; a query without it must be sent to every shard and the results merged, which is called a scatter-gather query.
So sharding brings three permanent costs. There are more moving parts to run, upgrade and back up. Some query shapes become slower or more expensive, and unique indexes must include the shard key. And the shard key is a long-lived decision: since MongoDB 5.0 we can reshard a collection online, but it copies the whole collection and needs spare capacity, so it is a project, not a setting.
- Spring service with the MongoDB driverconnects to mongos, not to the shards
- mongos routersroute each query by shard key
- Config server replica setholds chunk ranges and shard ownership
- Shard replica setseach holds a slice of the collection
4 layers, from the top down. Step through them one at a time.
Every layer below the application is new operational work compared with a single replica set.
2Step One: Find Out What Is Actually Growing
The first question is not how to scale but what is growing. In many systems the bulk of the volume is data nobody reads: audit events from five years ago, old order history, logs written into a business database. If 70 percent of a 4 TB cluster is records older than two years that are read a few times a month, we can move them to cheaper storage instead of scaling the hot cluster.
We can measure this with collection and index sizes from db.collection.stats(), and by grouping documents by age. A TTL index removes documents automatically after a time, which suits sessions and events. Online archive features of managed services, or a nightly job that copies old documents to object storage and deletes them, handle data that must be kept but rarely read. The working set, the data and indexes that queries touch often, is what must fit in memory, and it often grows much slower than the total size.
In this example 70 percent of the orders are old. Archiving them changes the problem from a cluster doubling every year to a hot dataset that grows with recent business only.
3Comparing the Four Options
Once we know the shape of the growth, we can compare the options with real numbers. Scaling up means moving to a larger instance: more RAM, more disk, more IOPS. It needs no code change and buys time cheaply. If a machine with twice the memory costs 1.8 times as much and gives us 18 months, that may be far cheaper than a team spending two quarters on sharding. The catch is the cost curve: the largest instances become disproportionately expensive, and there is a ceiling.
Splitting by domain or tenant means moving whole collections or customer groups to separate clusters. Catalogue data, orders and analytics events may sit in one cluster today only by history. Moving each to its own replica set keeps every query simple, and it gives blast-radius isolation: a runaway query in analytics can no longer slow down checkout. For a multi-tenant product, putting the largest tenants on dedicated clusters often solves both size and noisy-neighbour problems.
Changing database fits when the growth has a shape MongoDB serves poorly, such as append-only metrics that a time-series or column store handles far more cheaply. It is the most expensive option, so it needs a clear reason.
| Option | What it costs | What it gives | When it fits |
|---|---|---|---|
| Archive or tier old data | a job and a retrieval path | smaller hot set, cheaper storage | most volume is rarely read |
| Scale up | higher instance bill, no code | time, often one to two years | working set still fits a big machine |
| Split by domain or tenant | moving collections, new connections | simple queries, blast-radius isolation | unrelated data shares one cluster |
| Shard | operations, query limits, shard key | near-linear growth of one dataset | one dataset outgrows any machine |
| Change database | migration of code and data | a store built for the access pattern | workload is a poor fit for documents |
4How We Decide
A senior architect turns this into a decision with evidence. We project the hot dataset and the working set for three years after archiving and splitting, and we price the largest replica set that would hold them. If that price is acceptable for the planning horizon, sharding waits. If one collection will clearly exceed what a single replica set can serve, in write throughput or in working set, we shard that collection, and only that one.
We also write the decision down in an architecture decision record with the numbers, the options rejected and the trigger for revisiting it, such as the working set passing 70 percent of RAM. That record matters because the next person will face the same pressure in two years and should not have to rediscover the reasoning.
- Is most growth cold or expirable data?YesArchive, tier or add TTL firstNoLook at the hot data
- Do unrelated domains or big tenants share the cluster?YesSplit them into separate clustersNoKeep one cluster
- Does the projected working set fit the largest sensible machine?YesScale up and set a review triggerNoPlan sharding for that dataset
- Do the main queries carry a candidate shard key?YesShard with that keyNoRedesign queries or reconsider the store
4 steps in order. Play them, or step through them one at a time.
Each step removes growth that sharding would otherwise have to carry.
5If We Shard, Doing It Properly
When sharding is the answer, most of the work is in the shard key. A good key has high cardinality, spreads writes evenly, and appears in the queries that matter. We collect the real query patterns from the profiler or from slow query logs and check which share of traffic includes each candidate field. A monotonically increasing key such as a timestamp sends every new insert to the same shard, so hashed keys or compound keys such as tenantId plus orderId are common choices. MongoDB has tooling to analyse a candidate key against sampled queries (check your version for the exact command).
We also need people or a service that can run it. A managed service removes much of the routine work: balancing, config servers, upgrades and backups. Without one, we need operators who have run sharded clusters before. Finally, we rehearse: we practise resharding a production-sized copy, measure how long it takes and how much extra disk it needs, and test backup and restore across shards. A team that has done this once in staging is calm when it has to do it for real.
Notice that the second query still works, but it costs work on every shard. The shard key analysis tells us how much of our traffic looks like it.
6Follow-up questions
Why not just shard early, before it hurts?
Because sharding commits us to a shard key before we know our future query patterns, and it adds operational cost from day one. Scaling up and splitting by domain keep options open. The time to shard is when the evidence shows one dataset will outgrow a replica set within the planning horizon, early enough to do it calmly but not years ahead.
What makes a bad shard key?
Low cardinality, such as a country field with twenty values, which limits how many chunks can exist. A monotonically increasing value such as an ObjectId or timestamp, which sends all inserts to one shard. And a field that the main queries do not include, which turns most reads into scatter-gather queries across every shard.
7Conclusion
In this answer, we saw that sharding spreads one collection across several replica sets behind mongos, and that it brings lasting costs: more operations, limits on queries without the shard key, and a shard key that is hard to change. Before choosing it, we find out what is growing, archive or tier cold data, split unrelated domains or big tenants into their own clusters, and compare the cost curve of scaling up with the engineering cost of sharding. If we do shard, we choose the key from real query patterns, use a managed service or experienced operators, and rehearse resharding and recovery.
Open with
I would start by asking what exactly is growing, because 80 percent a year of total size is not the same as 80 percent of hot data. I would measure how much is old data we can archive, tier or expire with TTL indexes, and whether unrelated domains or a few big tenants share the cluster and could move to their own clusters, which also gives blast-radius isolation.
Then, if they want more
Then I would project the working set for the next three years and price the largest replica set that holds it. Scaling up is often the cheapest way to buy a year or two, so I compare that cost curve with the engineering cost of sharding.
Sharding brings real costs: more components to operate, scatter-gather for queries without the shard key, unique indexes tied to the key, and a shard key decision that lasts for years even though resharding exists. If one dataset still outgrows a single replica set, I shard that collection only.
I would choose the key from real query patterns, prefer a managed service or experienced operators, and rehearse resharding and restore on a production-sized copy. I would only change database if the workload is a poor fit for documents, such as pure time series. The decision and its review trigger go into an architecture decision record.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- MongoDB manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your company plans to shard its main MongoDB cluster because it is growing 80 percent a...": https://scrivio-interview-library.netlify.app/databases/mongodb/309651500c/