Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

Vertical scaling makes one machine bigger (more CPU, memory, faster disks); horizontal scaling adds more machines and spreads work among them. A startup's single PostgreSQL VM runs at 85 percent CPU and the team debates both options.

Compare the two approaches, and explain when scaling up is the right first move for this database.

Vertical scaling makes one machine bigger with no change to the application, which makes it the fastest fix for a single database, but it has a ceiling, rising cost at the top, a restart to resize and a large blast radius. Horizontal scaling adds machines and suits stateless tiers, but for a database it means replicas or sharding, with lag, routing and cross-shard queries. For this PostgreSQL VM, we first remove waste, then scale up and add a replica, and plan sharding only when growth will outgrow the largest sensible machine.

Why this question is asked

Every growing product reaches the day its database CPU graph stays above 80 percent. The team then debates: buy a bigger machine, or start distributing the data? Both camps have a point, and the right answer depends on where the load comes from and how fast it is growing. Interviewers ask this because the choice shows whether we understand what each approach really costs, especially for stateful systems. In this answer, we will recap both approaches, compare their costs, look at what horizontal scaling means for a database specifically, and walk through the order of steps for this startup's PostgreSQL.

1A Quick Recap of the Two Approaches

Vertical scaling, or scaling up, means giving one machine more resources: more CPU cores, more memory, faster disks. The software does not change; it just runs on a bigger box. Horizontal scaling, or scaling out, means adding more machines and spreading the work among them. The software must be able to split the work, which is easy for some components and hard for others.

The key distinction is state. A stateless application server, one that keeps no data between requests, can be copied freely; a load balancer spreads requests across ten copies as easily as across two. A database holds state, so spreading it across machines means deciding which machine holds which data and keeping copies consistent.

2Comparing Them

The table summarises the trade-offs; the paragraphs after it explain the ones that matter most for a database.

Scaling up versus scaling out
AspectVertical (scale up)Horizontal (scale out)
Application changesNoneStateless tiers: few. Databases: routing, sharding
Capacity ceilingLargest machine availableNear-linear for stateless tiers
Cost curveRises faster at the top endRoughly linear per node
ResizingRestart or failoverAdd nodes online
Failure impactOne machine, large blast radiusLosing one node loses a fraction
Database specificsSimple, strongly consistentReplica lag, cross-shard queries

Vertical scaling's great strength is that nothing changes. Queries, transactions, foreign keys and joins all keep working exactly as before, with the same strong consistency. And today's cloud machines are very large, with well over a hundred cores and terabytes of memory available, so the ceiling is far higher than many teams assume. A database at 85 percent on 8 cores has a lot of room before it reaches the largest machines.

Its weaknesses are real, though. There is a ceiling, and the price per unit of capacity usually rises at the top of the range. Changing instance size needs a restart, or a failover to a standby that was resized first. And everything rests on one machine, so its failure or a bad query affects every user.

3What Horizontal Scaling Means for a Database

For a database, scaling out takes two main forms. Read replicas are copies of the primary that receive its changes through streaming replication and serve read-only queries. They are fairly easy to add, but they lag behind the primary by milliseconds to seconds, so a user who writes something and immediately reads from a replica may not see it. The application must route reads and writes deliberately.

Sharding splits the data itself across several primaries, for example by customer id, so each holds a fraction of the rows and takes a fraction of the writes. It is the only way to scale writes beyond one machine, but it is a large change: every query must know which shard to go to, queries across shards become expensive or impossible, transactions across shards need special handling, and rebalancing data as shards fill up is an ongoing operational task. Tools like Citus for PostgreSQL help, but they do not remove these trade-offs.

4The Right Order for This Database

At 85 percent CPU, the first step is not to scale at all but to look for waste. PostgreSQL's pg_stat_statements view shows which queries use the most total time. Frequently, a handful of queries without the right index, or with an N+1 pattern, account for most of the load.

SQL
-- top queries by total execution time (pg_stat_statements extension enabled)
SELECT calls, round(total_exec_time) AS total_ms, round(mean_exec_time, 1) AS mean_ms, query
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 5;
-- e.g. 2,400,000 calls | 9,100,000 ms | 3.8 ms | SELECT * FROM orders WHERE customer_id = $1 ...
CREATE INDEX CONCURRENTLY idx_orders_customer ON orders (customer_id, created_at DESC);
-- that query drops to about 0.1 ms; total CPU may fall well below 85 percent
Step throughScaling a busy PostgreSQL primary
  1. Find waste firstpg_stat_statements, indexes, PgBouncer
  2. Still near the limit?After fixes
    YesScale up the instanceNoDone for now
  3. Add a replicaFailover plus read-only queries
  4. Writes will outgrow the largest sensible machine?From the growth forecast
    YesPlan shardingNoKeep scaling up and tuning

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

We also check for connection storms: hundreds of application instances each opening many connections, which costs PostgreSQL a process per connection and lots of CPU in context switching. A connection pooler such as PgBouncer in front of the database often frees noticeable CPU.

If, after that, the database still needs more capacity, we scale up, for example from 8 to 16 or 32 cores, which buys time with no application change. At the same time we add a replica: it gives failover if the primary dies, and it can serve heavy read-only queries such as reports or search, taking load off the primary. Sharding goes on the roadmap only when the growth forecast shows writes will exceed what the largest sensible machine can handle, which for many startups is years away.

5Keep the Application Tier Horizontal From the Start

While the database is best scaled up first, the application servers are the opposite. Keeping them stateless from day one, with sessions in Redis or in signed tokens, files in object storage and no local caches that must be consistent, costs very little and means we can add or remove instances freely behind a load balancer. It also gives redundancy for free: losing one of four instances loses a quarter of capacity, not the service. Making a stateful application tier stateless later is much harder than starting that way.

6Follow-up questions

What would make read replicas a bad fit for this application?

Replicas help only if a meaningful part of the load is reads that can tolerate slight staleness. If the load is mostly writes, replicas do nothing for it, since every replica must apply every write too. If most reads must see the latest data, such as a user immediately viewing what they just saved, or balance checks before a payment, routing them to a lagging replica causes bugs, and the workarounds (read-your-writes routing) add complexity. And if the bottleneck is lock contention on a few hot rows, more copies do not help at all.

When is scaling up not the right first move?

When the database is already on or near the largest sensible machine, when the growth curve will pass that size within months, or when the problem is availability rather than capacity, which needs replicas and failover rather than a bigger single node.

Does scaling up fix lock contention?

Usually not. Contention on hot rows limits throughput regardless of core count, and more cores can even make it worse. That needs a change in the data model or the transactions.

7Conclusion

In this answer, we compared scaling up, which needs no application changes but has a ceiling, rising cost and a large blast radius, with scaling out, which is near-linear for stateless tiers but means replication lag and sharding complexity for a database. For a PostgreSQL VM at 85 percent CPU, we first remove waste with pg_stat_statements, indexes and a connection pooler, then scale up and add a replica for failover and reads, and plan sharding only when growth will exceed the largest sensible machine, while keeping the application tier stateless and horizontal from the start.

What to say in the interviewAbout 90 seconds aloud

Open with

Vertical scaling means a bigger machine, and its big advantage for a database is that nothing changes: same queries, same transactions, same strong consistency, and cloud machines today go up to well over a hundred cores.

Then, if they want more

The limits are a ceiling on machine size, price that rises faster at the top end, a restart or failover to resize, and a big blast radius because everything is on one box. Horizontal scaling adds machines. For stateless app servers it is easy and gives near-linear capacity and redundancy.

For a database it means read replicas, which lag behind the primary, or sharding, which brings routing, cross-shard queries and rebalancing. For this PostgreSQL VM at 85 percent CPU, I would first look for waste: pg_stat_statements to find the top queries, missing indexes, N+1 patterns, and connection storms that PgBouncer can fix.

Often that alone brings the CPU down a lot. If it is still near the limit, I would scale up, say from 8 to 16 or 32 cores, and add a replica for failover and for heavy read-only queries. I would plan sharding only when the forecast shows writes outgrowing the largest sensible machine.

Meanwhile I would keep the application servers stateless and horizontally scalable from the start, because that costs little. Replicas are a poor fit if the load is mostly writes or reads that must be fresh.

About this answer

Last updated
13 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 "Compare the two approaches, and explain when scaling up is the right first move for this...": https://scrivio-interview-library.netlify.app/architecture/sd-fundamentals/1749dc2a7c/