“We already added two more shards, but why is one shard still running at 90% CPU?”
This was one of the first questions a customer asked us during a production performance review.
At first glance, the architecture looked perfectly fine.
The MongoDB cluster had been sharded.
Additional shards had recently been added to handle growing application traffic.
The balancer was running.
There were no hardware issues.
No replication problems.
Nothing unusual in the cluster logs.
Yet during every business peak, one shard consistently became overloaded while the remaining shards stayed relatively idle.
Adding more shards had increased the cluster size, but it hadn’t solved the performance problem.
As we investigated further, the issue became much clearer.
The problem wasn’t the number of shards.
It was the shard key.
A well-designed shard key allows MongoDB to distribute data, queries, and write operations naturally across the cluster. A poor shard key does exactly the opposite—it quietly concentrates workload until one shard becomes the busiest system in the entire architecture.
That is why choosing a shard key should never be treated as a simple database configuration step.
It is an architecture decision.
In this article, I don’t want to simply explain what a shard key is. MongoDB documentation already does that well.
Instead, I want to walk you through the way we usually evaluate shard keys during production health checks.
We’ll look at the symptoms that make us suspect a poor shard key, the questions we ask before recommending a change, the commands we use to validate our assumptions, and finally the characteristics that separate a good shard key from one that quietly limits scalability.
Before Talking About Shard Keys, Let’s Talk About the Problem They Solve
One thing I often notice is that many engineers start learning sharding by asking,
“What is a shard key?”
Personally, I think the better question is,
“Why do we need a shard key in the first place?”
Because once you understand the problem, the solution makes much more sense.
Imagine an e-commerce application that has grown steadily over the last few years.
Initially, everything runs on a single MongoDB server.
The application performs well.
Queries are fast.
Backups complete on time.
Life is good.
As the business grows, however, the number of customers increases, order history expands, and application traffic continues climbing. Eventually, simply adding more CPU or memory to the existing server is no longer enough.
At that stage, horizontal scaling becomes the natural choice.
Instead of asking one server to do all the work, MongoDB allows us to distribute the workload across multiple shards.
That sounds straightforward.
But here’s the next question.
How does MongoDB decide which shard should store a particular document?
It can’t randomly place documents across the cluster.
Otherwise, every query would need to search every shard.
That would defeat the purpose of sharding.
This is exactly where the shard key comes in.
A shard key is simply the field—or combination of fields—that MongoDB uses to decide where a document belongs.
Every insert, every query, and eventually every balancing operation is influenced by that decision.
Which means the shard key isn’t just deciding where data is stored.
It is quietly influencing:
- how evenly data is distributed,
- how efficiently queries are routed,
- how balanced write operations remain,
- and ultimately how well the cluster scales as the business grows.
And this is where many teams unknowingly make their first mistake.
They start looking for a unique field instead of the right field.
Those are not always the same thing.
A field may have millions of unique values and still become a poor shard key if applications rarely query it.
Another field may match every application query but create hotspots because new writes continuously target the same shard.
Choosing a shard key, therefore, is less about databases and more about understanding how the application behaves.
That’s exactly where experienced DBAs spend most of their time—not looking at MongoDB documentation, but understanding application workloads.
Because once the wrong shard key is chosen, every new document quietly reinforces that decision.
And by the time the business doubles in size, changing that decision becomes far more expensive than getting it right in the first place.
How Do You Know the Shard Key Is Actually the Problem?
This is probably one of the most common questions I hear from engineers who are new to MongoDB sharding.
“How do I know the shard key is the root cause?”
The honest answer is…
You don’t. At least not immediately.
One mistake I’ve seen repeatedly is blaming the shard key as soon as the application becomes slow.
But a production DBA rarely works like that.
High CPU can be caused by many things.
A slow query.
Missing indexes.
Network latency.
Application design.
Hardware limitations.
Replication issues.
Or even an overloaded storage subsystem.
The shard key is just one possibility.
That’s why I always tell people:
Never start by proving your assumption. Start by disproving every other possibility.
Once the obvious causes have been ruled out, that’s when I begin looking at how the workload is distributed across the cluster.
Because if the shard key is causing the problem, the cluster usually leaves small clues behind.
None of them individually prove anything.
But together, they start telling a story.
The First Thing I Check Isn’t CPU
Most monitoring dashboards immediately show CPU utilization.
Naturally, that’s where many people start.
Ironically, that’s not my first step.
CPU only tells me which server is busy.
It doesn’t tell me why.
Instead, I want to understand how MongoDB itself is distributing the data.
For that, I usually begin with one simple command.
sh.status()
I’m not running this command because I expect it to say “Wrong shard key detected.”
It never will.
What I’m looking for is something much more subtle.
- Is the data distributed reasonably across the shards?
- Are some shards holding significantly more chunks?
- Is the balancer constantly moving chunks around?
- Does the overall distribution make sense for the application’s workload?
Sometimes the answer is immediately obvious.
One shard owns considerably more chunks than the others.
Sometimes everything looks perfectly balanced.
And that’s where many people stop investigating.
But balanced chunks don’t necessarily mean balanced workload.
That is an important distinction.
I’ve seen clusters where every shard owned almost the same number of chunks, yet one shard handled nearly 70% of the application’s write traffic.
The chunk distribution looked healthy.
The workload wasn’t.
That tells me I need to keep digging.
A Healthy Cluster Doesn’t Always Mean a Healthy Workload
This is one of those production lessons that took me some time to appreciate.
When people hear the phrase “even distribution,” they usually think about storage.
As DBAs, we should think about workload.
Imagine three MongoDB shards.
Each stores roughly 500 GB of data.
At first glance, everything looks perfectly balanced.
But what if almost every new order created by the application lands on just one of those shards?
Storage remains balanced.
CPU doesn’t.
Memory doesn’t.
Disk activity doesn’t.
Neither does write latency.
Eventually, someone opens the monitoring dashboard and notices one shard running much hotter than the others.
The immediate reaction is often,
“Let’s add another shard.”
Unfortunately, adding another shard doesn’t automatically redistribute application behavior.
If the shard key continues sending most new writes to the same logical range, the new shard may contribute very little.
That’s why I rarely focus only on storage.
I pay much more attention to where the workload is actually happening.
The Next Question I Ask
Once I know where the workload is concentrated, the next question becomes surprisingly simple.
“Are the applications querying the cluster the way we expected?”
Remember something we discussed earlier.
A shard key doesn’t only decide where data is stored.
It also decides whether MongoDB can intelligently route queries.
This is where query analysis becomes extremely valuable.
Suppose an application frequently searches for customer orders.
One of the first things I want to know is whether those queries include the shard key.
If they do, MongoDB can usually perform a targeted operation.
If they don’t, MongoDB may have no option except asking every shard the same question.
That is what we call a scatter-gather query.
One or two scatter-gather queries won’t destroy a cluster.
Thousands of them every minute certainly can.
Whenever I suspect this behavior, I normally inspect the execution plan rather than guessing.
db.orders.find( { customer_id:1001 }).explain("executionStats")
I’m not interested in memorizing every field inside the output.
I’m simply asking one question.
Did MongoDB know exactly where to go, or did it have to search everywhere?
That single observation often explains why latency gradually increases as more shards are added.
Ironically, a larger cluster sometimes makes poorly targeted queries even more expensive.
Modern MongoDB Gives DBAs Better Tools
One thing I appreciate about newer MongoDB releases is that they help DBAs evaluate shard key quality before problems become severe.
A good example is the analyzeShardKey command.
db.adminCommand({ analyzeShardKey:"sales.orders", key:{ customer_id:1 }})
I don’t see this as a command that makes decisions for me.
Instead, I treat it like another experienced DBA sitting beside me and saying,
“Here’s what your workload currently looks like.”
It provides useful information about cardinality, query targeting, and write distribution.
But like every performance metric, it still needs interpretation.
No command can fully understand business behavior.
That part still belongs to the DBA.
This Is Usually Where the Real Problem Appears
By now we’ve looked at chunk distribution.
We’ve reviewed workload patterns.
We’ve examined query behavior.
Only after gathering all that information do I finally return to the shard key itself.
And quite often, the problem becomes obvious.
The shard key wasn’t technically wrong.
It simply stopped matching how the application had evolved.
That distinction is important.
Many shard keys work perfectly during the first year of an application.
The business grows.
Customer behavior changes.
Traffic patterns change.
New application features appear.
Suddenly, the same shard key that once looked ideal starts creating hotspots.
I’ve learned never to describe a shard key as good or bad.
Instead, I ask a different question.
“Is this shard key still the right choice for today’s workload?”
Because in production systems, yesterday’s perfect design can quietly become tomorrow’s bottleneck.
So… What Makes a Good Shard Key?
By this point in our investigation, we know something important.
The cluster isn’t slow because MongoDB cannot scale.
It’s struggling because the workload isn’t being distributed the way we expected.
Naturally, the next question becomes,
“How do we choose a better shard key?”
This is where many articles immediately start listing characteristics.
High cardinality.
Even distribution.
Stable values.
Avoid monotonically increasing fields.
Technically, all of those are correct.
But I don’t think that’s how experienced DBAs make the decision.
Whenever I evaluate a shard key, I ask myself four questions.
Not ten.
Not twenty.
Just four.
If a field answers all four reasonably well, it usually becomes a strong candidate.
Question 1 — Does It Match How the Application Actually Works?
I deliberately use the word application, not database.
Because databases don’t generate workload.
Applications do.
I’ve seen teams spend days debating whether order_id or customer_id would make a better shard key without asking one very simple question.
“Which field does the application actually use most often?”
Imagine an online shopping platform.
Every customer logs in and views their own orders.
Support teams search using customer information.
Recommendations are generated per customer.
Loyalty points belong to customers.
Almost every important operation starts with the customer.
Now imagine choosing transaction_id as the shard key simply because every transaction is unique.
Will MongoDB distribute data?
Yes.
Will the application benefit?
Not necessarily.
Many queries may still need to visit multiple shards because the application rarely searches by transaction ID.
This is something I always remind junior DBAs.
A technically good shard key isn’t always a good business shard key.
The best shard key is usually the one that understands the application better than the database.
Question 2 — Will the Workload Stay Balanced As the Business Grows?
This is where many shard key decisions begin to fail.
Not because they’re wrong.
Because they’re based on today’s workload.
Think back to the example we discussed earlier.
Using region looked like a perfectly reasonable decision.
Initially, every region generated similar traffic.
Nobody anticipated that five cities would eventually contribute nearly eighty percent of all customer orders.
The shard key didn’t suddenly become incorrect.
The business changed.
Production systems evolve much faster than database designs.
That’s why, whenever someone tells me,
“Our workload is evenly distributed today.”
I usually ask,
“What will it look like two years from now?”
Because if the answer is,
“We don’t know.”
then that uncertainty should become part of the shard key discussion.
A good shard key should survive business growth, not just today’s traffic pattern.
Question 3 — Will MongoDB Be Able to Route Queries Efficiently?
One of the biggest advantages of sharding is that MongoDB doesn’t always need to involve every shard.
When a query contains the shard key, MongoDB can usually identify exactly where the data lives.
That’s a targeted query.
Those are the kinds of queries we want to encourage.
Now imagine the opposite.
The application constantly searches using a field that has nothing to do with the shard key.
Every request suddenly becomes much more expensive.
Not because the query is poorly written.
Because MongoDB has fewer opportunities to target the correct shard.
Instead, it starts asking multiple shards the same question.
One scatter-gather query isn’t a concern.
Thousands every minute quickly become one.
That’s why I never evaluate a shard key without spending time understanding the application’s most common queries.
If the application rarely uses the proposed shard key in its filters, I immediately become cautious.
Because eventually the cluster will spend more time searching than serving.
Question 4 — Will This Field Remain Stable?
This final question is surprisingly easy to overlook.
Some fields change frequently.
Others almost never change.
Whenever a shard key changes, MongoDB may need to move documents between shards.
That isn’t free.
It consumes network bandwidth.
Storage activity.
CPU.
Balancer resources.
All of which could have been avoided by selecting a more stable field in the first place.
Identifiers such as customer IDs, account numbers or order IDs rarely change.
Customer locations, order status or departments often do.
One of the easiest ways to reduce future operational complexity is simply choosing a field that the business itself rarely modifies.
Sometimes the simplest decision turns out to be the most valuable one.
What About High Cardinality?
You’ll notice I haven’t mentioned cardinality until now.
That’s intentional.
Because I think it’s one of the most misunderstood topics in MongoDB sharding.
If you search online,
you’ll often find advice like:
“Always choose a high-cardinality field.”
That’s good advice.
But it’s incomplete.
High cardinality simply means there are many unique values.
Fields like:
- customer_id
- order_id
- transaction_id
are obvious examples.
Whereas fields like:
- status
- department
- gender
contain relatively few distinct values.
Naturally, MongoDB has more opportunities to spread data when there are more unique values.
But here’s something I’ve learned from production.
High cardinality is a requirement. It isn’t a guarantee.
I’ve seen beautifully distributed data with terrible query performance.
I’ve also seen moderate-cardinality fields outperform supposedly perfect shard keys simply because they aligned much better with application behavior.
Cardinality should always be evaluated together with:
- query patterns,
- workload distribution,
- future business growth,
- and write behavior
Looking at cardinality alone is like choosing a house based only on its size.
It tells you something.
But certainly not everything.
Your Work Doesn’t End After Deployment
One misconception I occasionally hear is:
“We’ve selected the shard key. We’re done.”
In reality, that’s where monitoring begins.
Applications rarely remain unchanged.
New features are introduced.
Marketing campaigns drive unexpected traffic.
Customer behavior evolves.
Sometimes the shard key that worked perfectly two years ago quietly becomes the bottleneck.
That’s why monitoring isn’t just about checking whether the cluster is healthy.
It’s about checking whether the original design assumptions are still valid.
When reviewing a production cluster, I usually pay attention to questions like:
- Is one shard consistently busier than the others?
- Are chunk migrations becoming more frequent?
- Has query latency increased even though hardware hasn’t changed?
- Are scatter-gather operations becoming more common?
- Is the balancer constantly trying to redistribute data?
None of these individually proves the shard key is wrong.
But together, they often tell an interesting story.
Production monitoring isn’t about reacting to failures.
It’s about recognizing patterns before users notice them.
What If the Shard Key Really Needs to Change?
Eventually, some teams reach a difficult conclusion.
The application has evolved.
The workload has changed.
The existing shard key no longer fits the business.
Years ago, this was one of the biggest challenges in MongoDB.
Changing a shard key usually meant rebuilding collections or performing complex migration activities.
Modern MongoDB versions have made this process much easier through resharding.
That’s a significant improvement.
But I still encourage teams to think of resharding as a planned architectural change, not as a routine maintenance task.
Resharding consumes resources.
It generates additional network traffic.
It requires careful planning.
And most importantly, it deserves the same level of preparation as any other production change.
Before starting a resharding operation, I always recommend answering a few practical questions:
- Have we confirmed that the current shard key is truly the problem?
- Have we evaluated alternative shard keys using production-like workloads?
- Do we have sufficient cluster capacity to handle the resharding process?
- Have backups been verified?
- Is there a rollback strategy if something doesn’t go as expected?
Just because resharding is possible doesn’t mean it should become the first solution.
Quite often, the best solution is still choosing the right shard key during the initial design phase.
Final Thoughts
A shard key isn’t just a field in a collection.
It’s a decision that influences how MongoDB stores data, routes queries, balances workloads, and scales as the business grows.
That’s why I believe choosing a shard key should never begin with a database command.
It should begin with understanding the application.
How users interact with it.
How data grows.
How queries behave.
And perhaps most importantly, how the business is likely to evolve over the coming years.
After working with production MongoDB environments, one lesson has stayed with me.
No one intentionally chooses a poor shard key.
The problem is that applications change much faster than database designs.
A shard key that looked perfect on day one may quietly become the biggest scalability bottleneck three years later.
That’s why experienced DBAs don’t simply choose a shard key and move on.
They continue validating that decision as the application evolves.
Because successful sharding isn’t about adding more servers.
It isn’t about distributing more data.
It’s about distributing the right workload in the right way for the right application.
And if there’s one message I’d like you to take away from this article, it’s this:
Don’t choose a shard key because it looks technically correct. Choose it because it reflects how your application behaves today—and how you expect it to behave tomorrow.
Trackbacks/Pingbacks