Quick revision
The short answer
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.
What to remember
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.
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.
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.
| Pods | Requests/s | DB CPU | p99 latency |
|---|---|---|---|
| 3 | 1,500 | 30% | 60 ms |
| 6 | 3,000 | 60% | 70 ms |
| 10 | 4,600 | 92% | 140 ms |
| 20 | 4,700 | 99% | 600 ms |
| 30 | 4,300 | 100%, more lock waits | 1.4 s |
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.
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.
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.
| Fix | DB CPU | Connection count | Hot rows |
|---|---|---|---|
| Smaller pools, PgBouncer | no | yes | no |
| Read replicas, caches | yes, for reads | partly | no |
| Fewer queries per request | yes | partly | partly |
| Remove hot counters | partly | no | yes |
| Partition data across databases | yes, for writes | yes | yes, 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.
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/