Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

One shard in a cluster is at 90 percent CPU while others are idle. The shard key is {tenantId: 1} and one tenant generates 40 percent of traffic. Explain and fix it.

With {tenantId: 1} as the shard key, every document of the big tenant has the same key value, so they must all live in one chunk range that cannot be split below a single value, a jumbo chunk, and the shard holding it takes the tenant's 40 percent of traffic. The key has a high-frequency value, so it cannot spread the load. We fix it by refining the shard key with a suffix field, refineCollectionShardKey from MongoDB 4.4, for example to {tenantId: 1, orderId: 1}, or by resharding to a better key with reshardCollection from 5.0, which copies the data and needs capacity planning; if isolation is the goal, zones can pin the big tenant to dedicated shards.

Why this question is asked

Sharding by tenant is a natural choice for a multi-tenant product: every query includes the tenant, so every query is targeted, and each tenant's data stays together. It works until one tenant grows much faster than the others. Then the design that kept a tenant's data together also keeps all of that tenant's load together, on one machine. Interviewers ask this scenario because it tests whether we understand chunks and their limits, and whether we know the tools MongoDB now provides to change a shard key online. In this answer, we will recap chunks and why they split, see why this tenant cannot be split, refine the key, compare it with resharding, look at zones for isolation, and check that the fix actually spreads the writes.

1A Quick Recap: Chunks and Splitting

In ranged sharding, the shard key's value space is divided into chunks, contiguous ranges of key values, each owned by one shard. When a chunk grows too large, MongoDB splits it at a key value in the middle, and the balancer moves chunks between shards to even out the data. Splitting only works at a boundary between two different shard key values, because a chunk is defined by key values.

So a chunk can never be smaller than all the documents that share one shard key value. If a single value has a very large share of the documents, the chunk containing it cannot be split, and MongoDB marks it as a jumbo chunk. The balancer also cannot move a jumbo chunk normally, so it stays where it is.

2Why One Shard Is at 90 Percent CPU

Here the key is tenantId alone, and one tenant generates 40 percent of all traffic.

Java
sh.shardCollection("shop.orders", { tenantId: 1 });
sh.status();
// chunks:
// { tenantId: 1 } -> { tenantId: 17 } on shard A
// { tenantId: 17 } -> { tenantId: 18 } on shard B jumbo
// { tenantId: 18 } -> { tenantId: MaxKey } on shard C
// tenant 17 alone: 40 percent of reads and writes, all on shard B
Load by shard before and after refining the key
ShardShare of operations beforeAfter a hashed orderId suffix
A20 percent33 percent
B70 percent, including all of tenant 1734 percent
C10 percent33 percent
Illustrative numbers: once tenant 17 can be split, its load spreads over every shard.

Every order of tenant 17 has the same shard key value, 17, so all of them belong to the single range from 17 to 18. MongoDB cannot cut that range any finer, so the chunk is jumbo, it stays on shard B, and every read and write for tenant 17 lands there. Shard B runs at 90 percent CPU while A and C are lightly loaded. The underlying cause is the shard key's distribution: it has a value with very high frequency, so it cannot spread that value's load, no matter how many shards we add.

3Fix 1: Refine the Shard Key With a Suffix

From MongoDB 4.4 we can refine a shard key by adding fields at the end, without moving data. The existing prefix, tenantId, stays, so every query that targets a tenant still works, but now documents of one tenant have different shard key values and chunks can split inside the tenant.

Java
// 1. The index for the new key must exist first
db.orders.createIndex({ tenantId: 1, orderId: 1 });
// 2. Refine the key: a metadata change, no data is copied
db.adminCommand({
refineCollectionShardKey: "shop.orders",
key: { tenantId: 1, orderId: 1 }
});
// 3. The jumbo chunk can now split at orderId boundaries and the balancer moves pieces
sh.status(); // tenant 17 now spans several chunks on A, B and C

Notice a subtle catch in the suffix. If orderId increases over time, then within tenant 17 all new orders still land in the tenant's last chunk, the one with the highest orderIds, so new writes for the tenant are again concentrated on one shard, even though the old data is spread. Reads of existing orders spread well, but inserts do not. To spread inserts too, the suffix should not be monotonic, for example a hashed field, {tenantId: 1, orderId: 'hashed'}, or a random or well-distributed identifier. Compound keys with one hashed field are supported from 4.4; check your version's rules for which positions may be hashed and whether refining to a hashed suffix is allowed, or use resharding for that change.

After refining, queries that include tenantId and orderId target one shard, and queries with only tenantId go to the shards holding that tenant's chunks, which for tenant 17 is now several shards, a reasonable trade.

4Fix 2: Reshard to a Better Key

If the key needs to change more than a suffix allows, MongoDB 5.0 added reshardCollection, which redistributes the collection to a completely new shard key while the application keeps reading and writing.

Java
db.adminCommand({
reshardCollection: "shop.orders",
key: { tenantId: 1, orderId: "hashed" }
});
// copies every document into the new distribution, applies ongoing writes,
// then blocks writes briefly (about 2 seconds by default) to switch over

Resharding is a full copy. Each shard needs enough free disk space and spare CPU and I/O to hold and build the new distribution while still serving traffic, and it takes hours for large collections. So we plan capacity, run it in a quiet period, and monitor progress with the currentOp output for the resharding operation. Check your version's documentation for the exact space requirements and limits, since they have changed between releases.

5Zones for Isolation

Sometimes the goal is not even spreading but isolation: the big tenant pays for dedicated capacity, or we do not want it to affect everyone else. Zones let us pin a range of shard key values to specific shards.

Java
sh.addShardToZone("shardD", "bigTenants");
sh.addShardToZone("shardE", "bigTenants");
sh.updateZoneKeyRange("shop.orders",
{ tenantId: 17, orderId: MinKey },
{ tenantId: 18, orderId: MinKey },
"bigTenants");
// the balancer moves tenant 17's chunks to shards D and E only
Step throughChoosing the fix for a hot tenant
  1. Is the problem a single key value?jumbo chunk in sh.status
    YesShard key needs more granularityNoLook at other causes
  2. Can a suffix field fix it?refine is metadata only
    YesrefineCollectionShardKeyNoreshardCollection
  3. Should the tenant be isolated?cost and noisy-neighbour concerns
    YesAdd zones for dedicated shardsNoLet the balancer spread it
  4. Verify load per shardCPU, ops and chunk counts

4 steps in order. Play them, or step through them one at a time.

Combined with the refined key, tenant 17's data spreads across the two dedicated shards and nobody else's data lives there. Other tenants share the remaining shards. Zones are also useful for data residency, keeping a region's tenants on shards in that region.

6Follow-up questions

Why not just give shard B a bigger machine?

That buys time, but the tenant's load stays on one shard and grows with the tenant. The point of sharding is horizontal scaling, and a key that cannot split the largest tenant defeats it.

How would we have caught this earlier?

By checking shard key frequency when designing: if any single tenant could plausibly exceed one shard's share, the key needs a suffix from the start. Monitoring jumbo chunks and per-shard operation counts would also have warned us before CPU hit 90 percent.

Does refining the key change queries?

Queries that include tenantId still target the tenant's chunks, now possibly on several shards. Unique indexes and the application code are unchanged, though inserts must include the new suffix field, which every order already has.

7Conclusion

In this answer, we saw that with {tenantId: 1} all documents of one tenant share a single key value, so they form a jumbo chunk that cannot split or move, and the shard holding it absorbs the tenant's 40 percent of traffic. We refined the key with a suffix using refineCollectionShardKey, making sure the suffix is not monotonic so new writes spread too, considered reshardCollection for a full change with its capacity cost, and used zones when the big tenant should be isolated on dedicated shards.

What to say in the interviewAbout 90 seconds aloud

Open with

The cause is the shard key's distribution. With tenantId alone, every document of the big tenant has the same key value, and chunks can only be split between different values.

Then, if they want more

So that tenant's data sits in one chunk that can't be split, a jumbo chunk, and the balancer can't move it normally. The shard holding it gets all of that tenant's forty percent of traffic, which is why one shard is at ninety percent while the others are idle. Adding shards wouldn't help.

The fix is to give the key more granularity inside a tenant. From 4.4 I can use refineCollectionShardKey to add a suffix, for example tenantId plus orderId, after creating the matching index. It's a metadata change, the jumbo chunk can then split at orderId boundaries and the balancer spreads it.

One catch: if orderId increases over time, new orders for that tenant still go to its last chunk, so I'd prefer a hashed or non-monotonic suffix. If the key needs a bigger change, reshardCollection from 5.0 moves data to a new key online, but it copies the whole collection, so I'd plan disk, CPU and timing.

And if the business wants that tenant isolated, zones can pin its key range to dedicated shards. Afterwards I'd verify CPU, operations and chunk counts per shard.

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 "One shard in a cluster is at 90 percent CPU while others are idle. The shard key is...": https://scrivio-interview-library.netlify.app/databases/mongodb/73f3f2b22b/