Quick revision
The short answer
Shard only after the cheaper options are exhausted: query tuning, caching, read replicas, archiving old data and larger instances. When sharding is truly needed, compare building it in-house with adopting a distributed SQL database on cost, latency and the skills we have. Choose shard keys per domain together with the data owners, because they shape each system for years, build the routing, migration and operations tooling once as a shared platform rather than per team, and stage the work by risk with a rollback path at every step.
What to remember
In this answer, we saw that sharding is the right choice only after query tuning, caching, replicas, archiving and larger instances stop buying enough time. Then we compare in-house sharding with distributed SQL on cost, latency and skills, choose shard keys per domain with the data owners, build routing, migration and operations tooling once for everyone, and stage the work by risk with a rollback path at each step, with the platform team building the machinery and domain teams owning their migrations.
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.
Shard only after the cheaper options are exhausted: query tuning, caching, read replicas, archiving old data and larger instances. When sharding is truly needed, compare building it in-house with adopting a distributed SQL database on cost, latency and the skills we have. Choose shard keys per domain together with the data owners, because they shape each system for years, build the routing, migration and operations tooling once as a shared platform rather than per team, and stage the work by risk with a rollback path at every step.
Why this question is asked
When several core databases approach their vertical limits at the same time, the organisation faces one of its most expensive technical decisions. Sharding done too early wastes years of engineering on complexity that was not needed; done too late, it happens in a crisis. Interviewers ask this leadership question to see whether we can decide when, choose how and organise who does the work. In this answer, we will go through the cheaper options first, then the build-or-adopt choice, shard keys and ownership, shared tooling, and staging with rollback.
1First, Exhaust the Cheaper Options
Sharding changes how every query, transaction and operation works for the life of the system, so it should be the answer only when cheaper options cannot buy enough time. For each database, we go through them with numbers. Query tuning comes first: often a handful of queries use most of the CPU, and an index or a rewrite cuts load by a third. Caching removes repeated reads. Read replicas take read-only traffic off the primary. Archiving old data shrinks tables and indexes, so more of the working set fits in memory. Larger instances buy time quickly.
The question for each database is how many months of growth these options buy. If tuning and archiving buy three years at the current growth rate, sharding can wait, and the time is better spent elsewhere. If they buy six months, the decision is urgent.
- Measure load and growth rateper database
- Tuning, caching, replicas, archiving buy 2+ years?YesDo those; revisit yearlyNoContinue
- Write load the main limit?YesPlan partitioningNoReplicas and caches may be enough
- Compare in-house sharding vs distributed SQL
- Choose keys with data owners, stage by risk
5 steps in order. Play them, or step through them one at a time.
2In-House Sharding or a Distributed SQL Database?
Building sharding in-house means our own routing, resharding and cross-shard tooling on top of PostgreSQL or MySQL. We keep familiar databases and full control, but we own a complex system forever. Distributed SQL databases, such as CockroachDB, YugabyteDB or cloud services such as Spanner, partition data automatically and keep SQL and transactions across partitions.
The comparison has three parts. Cost includes licences or cloud prices and, more importantly, the engineers needed to build and run each option. Latency matters because distributed transactions need coordination between nodes, so some operations are slower than on a single primary, which we must measure with our own workload. Skills matter because the team that runs databases today knows PostgreSQL deeply; a new database brings new failure modes to learn. There is no universal answer, and the choice can differ between domains.
| In-house sharding | Distributed SQL | |
|---|---|---|
| Control | full | limited to the product |
| Engineering to build | large, ongoing | smaller, migration and tuning |
| Cross-shard transactions | avoided or sagas | supported, with latency cost |
| Operational skills | existing (PostgreSQL) | new to learn |
| Running cost | familiar instances | licence or service price |
3Shard Keys Chosen With the Data Owners
A shard key decides which queries are cheap and which are expensive for years, so it is a domain decision, not only a technical one. The orders domain may shard by customer, the inventory domain by warehouse, a business platform by tenant. The teams who own the data know the access patterns, the large customers and the queries that must stay fast, so they choose with us.
We make the trade-offs explicit in a short design record per domain: the key, which queries become cross-shard, how large customers are handled and how resharding works. That record will be read by engineers who join years later.
4Build Shared Tooling Once
If each team shards on its own, the organisation pays for the same hard problems several times: routing libraries, schema migrations across many shards, backups and restores per shard, moving data between shards, and dashboards that show every shard. And each version has its own bugs.
So a platform or database team builds these once: a routing library with logical shards, a migration runner that applies schema changes to every shard safely, rebalancing tools and standard monitoring. Domain teams own their key choice and their data; the platform team owns the machinery. That split also answers who does the work: the platform team builds the tooling and leads the first migration, and domain teams carry out their own migrations with platform support.
5Stage the Work by Risk, With Rollback
We start with the domain where sharding is both needed and least risky, ideally one with clear per-customer access and few cross-domain joins. It proves the tooling and teaches the organisation. The most critical domain, such as payments, comes later, when the tools are mature.
Within each migration, every step has a rollback path: dual writes with the old database as the source of truth, shadow reads to compare, switching reads before writes, and keeping the old path alive for a period after cutover. A migration that cannot be reversed at a step should not proceed past it until we are sure. We report progress to leadership as headroom gained per database, so the investment is visible.
6Follow-up questions
How do you know when you are close to the vertical limit?
Track utilisation of the primary over time, CPU, IO, memory hit ratio and connection counts at peak, against the largest instance available, and project the growth rate. If peak CPU grows 4 percent a month and we are at 60 percent on the second largest instance, we can estimate how many months remain and plan backwards from that.
What is the biggest risk in a sharding programme?
Choosing the wrong key, because it is the hardest thing to change later. The second is underestimating cross-shard needs, such as reporting and support searches. Both are reduced by involving data owners early and listing the important queries before deciding.
Can archiving really make a difference?
Often a large one. In many systems most rows are older than a year and rarely read. Moving them to cheaper storage shrinks indexes and tables, more of the hot data fits in memory, and maintenance such as vacuum and backups gets faster. It can buy years for a database that is mostly history.
7Conclusion
In this answer, we saw that sharding is the right choice only after query tuning, caching, replicas, archiving and larger instances stop buying enough time. Then we compare in-house sharding with distributed SQL on cost, latency and skills, choose shard keys per domain with the data owners, build routing, migration and operations tooling once for everyone, and stage the work by risk with a rollback path at each step, with the platform team building the machinery and domain teams owning their migrations.
Open with
I would start by not sharding until I have to. For each database I would measure load and growth and go through the cheaper options with numbers: tune the top queries, add caching, move reads to replicas, archive old data and scale up the instance.
Then, if they want more
If those buy two or more years, we do them and revisit yearly. If they buy months, and writes are the limit, we plan partitioning.
Then I would compare building sharding in-house on PostgreSQL with adopting a distributed SQL database, looking at the engineers needed to build and run each, latency measured on our own workload, especially for transactions, and the skills of the team who will run it; the answer can differ per domain.
Shard keys are chosen with each domain's data owners, because they decide which queries are cheap for years, and we write the trade-offs down. The tooling, routing with logical shards, schema migrations across shards, rebalancing and monitoring, is built once by a platform team, while domain teams own their keys and migrations.
Finally I would stage it: start with a domain that needs it and is low risk, keep a rollback path at every step with dual writes and shadow reads, and report headroom gained to leadership.
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 official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
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 "Several core databases in your organisation are approaching their vertical limits. How...": https://scrivio-interview-library.netlify.app/spring-boot/scalability/19b692d014/