Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

A Spring Boot service scales horizontally from 3 to 30 pods but throughput stops growing after 10 pods. It uses one PostgreSQL database. What limits scaling here?

The limit is almost certainly the single shared PostgreSQL database. Every pod sends its queries to the same CPU, disks and rows, so beyond a point more pods only add contention; each pod also brings its own connection pool, so total connections grow with pods and can exceed what the database can serve; and hot rows and locks, such as a counter every request updates, serialise work. Reads can scale with replicas and caches, writes need data partitioning or less work per request, and a connection proxy such as PgBouncer helps with connection counts but not with CPU.

Why this question is asked

Horizontal scaling looks magical at first: double the pods, double the throughput. Then it stops, and adding pods makes things slower. Interviewers ask this to see whether we can find the shared resource that does not scale with the pods. In this answer, we will recap why stateless pods scale, then look at the three ways one database limits them: its own capacity, connection counts and hot rows, and finish with what actually helps for reads and for writes.

1A Quick Recap: What Scales and What Does Not

Stateless pods scale horizontally because each one brings its own CPU and memory and they share nothing with each other. Ten pods have ten times the CPU of one. But every request also uses the database, and there is only one primary. Its CPU, disk throughput and memory are fixed, no matter how many pods talk to it.

So throughput grows with pods only while the database has spare capacity. Once it is saturated, extra pods just queue for it. This is a direct consequence of Amdahl's law in another form: the part of the work that cannot be spread out limits the whole.

Throughput as pods are added (illustrative)
PodsRequests/sDB CPUp99 latency
31,50030%60 ms
63,00060%70 ms
104,60092%140 ms
204,70099%600 ms
304,300100%, more lock waits1.4 s
After 10 pods the database is saturated: more pods add waiting, not throughput.

2Limit 1: One Database's CPU, Disks and Rows

The first limit is raw capacity. If each request costs 2 ms of database CPU and the database has 8 cores, it can serve at most about 4,000 such requests per second, whatever the number of pods. We confirm this from the database side: CPU near 100 percent, the number of active sessions rising, and pg_stat_statements showing which queries use the time.

Notice that beyond saturation, throughput can even fall. More concurrent queries mean more context switching, more lock waits and less effective use of memory caches, so the database does less useful work per second.

3Limit 2: Connections Grow With Pods

Each pod has its own HikariCP pool. With a pool of 20 connections, 30 pods can open 600 connections. In PostgreSQL every connection is a separate server process with its own memory, so hundreds of connections cost memory even when idle, and the default max_connections of 100 is easy to hit. When it is hit, new pods fail to start or requests fail with 'too many clients'.

Even below the limit, many active connections hurt. If 600 queries are running at once on 8 cores, each one gets a tiny share of CPU and they all take longer. A smaller number of connections, around a few times the core count for active queries, usually gives higher throughput.

SQL
-- On the database
SELECT count(*), state FROM pg_stat_activity GROUP BY state;
-- 412 idle
-- 96 active <- 96 queries competing for 8 cores
SHOW max_connections; -- 500
-- 30 pods x pool 20 = 600 possible: new pods would fail at 500

4Limit 3: Hot Rows and Locks

The third limit is contention on specific rows. Suppose every request increments a counter, such as a daily statistics row or a stock level for a popular product. An UPDATE locks that row until its transaction commits, so all requests that touch it queue up one behind the other. However many pods we add, that row is updated one transaction at a time.

SQL
-- Every request runs this inside its transaction
UPDATE daily_stats SET orders = orders + 1 WHERE day = CURRENT_DATE;
-- Each transaction holds the row lock until commit, about 5 ms
-- Maximum rate on this row: about 1000 / 5 = 200 per second, with any number of pods
Step throughRequests queue for one hot row
Pod 1Pod 2Database row lock
UPDATE daily_stats ... (gets the lock)
UPDATE daily_stats ... (waits)
COMMIT, lock released
now gets the lock
COMMIT

5 messages in order. Play them, or step through them one at a time.

A row updated by every request serialises those requests.

Fixes for hot rows change the design: aggregate counts asynchronously from events, keep per-pod or per-shard counters that are summed when read, or shorten the transaction so the lock is held for less time.

5What Helps: Reads, Writes and Connection Counts

Reads are the easier half. Read replicas, copies of the database that apply the primary's changes slightly later, can serve queries that tolerate a little staleness, and caches can serve the same data many times without touching the database. In Spring we can route read-only transactions to a replica with a routing data source, or use a separate data source for reporting.

Writes are harder, because every write must go to the primary. Either we do less work per request, for example fewer queries, batched writes and no hot counters, or we partition the data across several databases, by customer or tenant id, so that each database carries a share of the writes.

A connection proxy such as PgBouncer solves limit 2: thousands of client connections are multiplexed onto a small number of server connections. But it does nothing for limits 1 and 3. If the database CPU is at 100 percent, a proxy only changes where requests wait.

What each fix addresses
FixDB CPUConnection countHot rows
Smaller pools, PgBouncernoyesno
Read replicas, cachesyes, for readspartlyno
Fewer queries per requestyespartlypartly
Remove hot counterspartlynoyes
Partition data across databasesyes, for writesyesyes, if keys spread

6Follow-up questions

How do you prove the database is the limit?

Correlate the curves. When throughput flattens, look at database CPU, active sessions and lock waits: if they hit their limits at the same moment, the database is the bottleneck. Pod CPU staying low while latency rises is another sign that pods are waiting on something shared.

Would a bigger database instance fix it?

For a while, if the limit is CPU or memory. It is often the fastest relief. It does not fix hot rows, because a row lock serialises transactions on any hardware, and it has a ceiling: the largest instance is the end of that road.

Why does throughput drop when we add even more pods?

Because contention grows. More concurrent connections compete for CPU and locks, the database spends more time switching between them and waiting, and connection churn adds overhead. Past saturation, extra load lowers useful work.

7Conclusion

In this answer, we saw why a service stops scaling at 10 pods on one PostgreSQL database. The shared database's CPU, disks and rows are fixed, so pods beyond saturation only add contention; each pod's pool multiplies total connections; and hot rows serialise work regardless of pod count. Reads scale with replicas and caches, writes need less work per request or partitioning, and PgBouncer solves connection counts but not CPU.

What to say in the interviewAbout 80 seconds aloud

Open with

The pods scale, but they all share one PostgreSQL primary, and that is where it stops. First, the database's CPU and disks are fixed. If each request costs a couple of milliseconds of database CPU, eight cores cap throughput no matter how many pods there are, and past saturation more concurrent queries make things worse through context switches and lock waits.

Then, if they want more

Second, connections: every pod has its own Hikari pool, so thirty pods with twenty connections can open six hundred, each one a PostgreSQL process, which can hit max_connections and slows everything even before that.

Third, hot rows: if every request updates the same counter row, the row lock serialises those transactions, so at five milliseconds per transaction that row handles about two hundred updates a second whatever we do with pods. To prove it I would look at database CPU, active sessions and lock waits at the moment throughput flattens.

For fixes, reads scale with replicas and caches. Writes need less work per request, removing hot counters, or partitioning data across databases. And PgBouncer fixes the connection count, but not CPU or locks, so on its own it just moves where requests wait.

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 "A Spring Boot service scales horizontally from 3 to 30 pods but throughput stops growing...": https://scrivio-interview-library.netlify.app/spring-boot/scalability/319a0024e1/