Scrivio Interview library
LeadershipAdvanced7 min read · updated 12 November 2026

Teams keep raising database pool sizes to fix timeouts, and the shared database's performance is degrading. What policy and tooling would you introduce?

I would treat database connections as a budgeted shared resource with a named owner, and require evidence, such as connection hold time and pending threads, before any pool increase. Most timeouts come from connections held too long, so the first step is always to shorten hold time: long transactions, remote calls inside transactions and Open Session in View. Per-service dashboards and saturation alerts make this visible, and when demand genuinely grows we add a pooler or split the database instead of raising pools.

Why this question is asked

When a service times out waiting for a connection, raising the pool size is the quickest change anyone can make, and it often seems to work for a week. On a shared database, though, every team doing it at once pushes the database past its parallel capacity, and then every service gets slower, including the ones that changed nothing. Interviewers ask this at senior levels because the answer is mostly policy and habit, not code: we need to change how teams decide, and give them the tools to decide well. In this answer, we will recap why bigger pools hurt a shared database, then set up a connection budget, an evidence rule for increases, the hold-time fixes that should come first, the dashboards and alerts that make it all visible, and the options for real growth.

1Why Bigger Pools Hurt a Shared Database

A connection pool limits how many statements a service can run on the database at the same moment. When the pool is full, new requests wait in the application. That waiting shows up as a timeout, and the natural reaction is to make the pool bigger. But the database can only run as many queries truly in parallel as it has cores and I/O capacity. A database with 16 cores might serve around 40 busy connections well; if six services each raise their pools from 20 to 60 and run four instances each, that is 1,440 possible connections.

Once the database is past its capacity, more active sessions mean more context switching and more lock contention, so every query slows down. Slower queries hold connections longer, which causes more timeouts, which causes more requests to raise pools. The fix that works locally makes the shared system worse. That feedback loop is what our policy must break.

2Treat Connections as a Budget With an Owner

The first change is to make the database's connection capacity a named, owned budget. The owner, usually the platform or database team, states what the database can serve, keeps a reserve for administration, migrations and monitoring, and allocates the rest to services. Each service's allocation is per service, not per instance, so the team must divide it by its maximum instance count, including autoscaling.

Connection budget for a shared PostgreSQL database (example)
ConsumerBudgetInstancesPool per instance
Reserve: admin, migrations, monitoring20--
orders-service60610
billing-service40410
catalog-service2438
reporting-jobs1628
Unallocated40--
200 connections in total; each team divides its budget by its maximum instance count.

With the budget written down, a pool increase is no longer a one-line change that only the service team sees. It is a request against a shared resource, and the owner can see whether it fits. The budget is reviewed when services grow, so it is a planning tool and not just a gate.

3Ask for Evidence Before Any Increase

The second change is an evidence rule. A request for a bigger pool comes with metrics from the period of the problem: active and pending connections, the time threads waited to acquire a connection, and the average time a connection is held. HikariCP publishes all of these through Micrometer, so every Spring Boot service already has them.

Little's law makes the evidence easy to read. The connections a service needs equal its throughput times its average hold time. If a service handles 300 requests per second and holds each connection for 30 ms, it needs about 9 connections. If its pool of 20 is always full, the hold time must really be much higher, and that is the number to investigate. So the request often answers itself: the data shows a hold-time problem, not a pool-size problem.

Java
// The question every pool-increase request must answer
double throughput = 300; // requests per second at peak
double holdMs = 30; // average hold time measured from metrics
int needed = (int) Math.ceil(throughput * holdMs / 1000); // 9 connections
double holdWithHttpCall = 400; // the same request with a remote call inside the transaction
int neededSlow = (int) Math.ceil(throughput * holdWithHttpCall / 1000); // 120 connections

4Fix the Hold Time First

In almost every case I have seen, the real problem is connections held too long. Three causes are common. The first is long transactions: a @Transactional method that loads a large graph, processes it in memory and writes at the end holds its connection for the whole time. The second is remote calls inside transactions: calling a payment API or another service while a transaction is open keeps the connection busy for the whole network round trip, often hundreds of milliseconds. The third is Open Session in View, a Spring Boot feature (spring.jpa.open-in-view, which is on by default and logs a warning at startup) that keeps the persistence context, and with lazy loading the connection, open for the whole web request, including rendering the response.

Each fix shortens hold time directly. We move remote calls before or after the transaction, keep transactions around the database work only, and set spring.jpa.open-in-view=false, fixing any lazy loading errors with fetch joins or DTO queries. Going from 400 ms to 30 ms of hold time cuts the needed connections by more than ten times, with no change to the database at all.

5Make It Visible: Dashboards and Alerts

Policy only works if people can see the state of the system. The platform team provides a standard dashboard per service with active, idle and pending connections, acquire time, and connection usage time, next to the database's view: total sessions per application name, sessions idle in transaction and the top wait events. Setting each service's application name in the JDBC URL makes the database's view readable.

Alerts should fire on saturation before timeouts: for example, pending connections above zero for five minutes, or acquire time p99 above 50 ms. A second alert on the database side, total connections above 80 percent of the limit, warns the owner that the budget is nearly used. Teams then see the problem, with the evidence attached, before they reach for the pool setting.

Step throughHandling a pool-increase request
  1. Team reports connection timeouts
  2. Attach metricsactive, pending, acquire time, hold time at peak
  3. Is hold time normal for the work?
    YesCheck the budgetNoFix long transactions, remote calls, OSIV first
  4. Does the increase fit the budget?
    YesApprove and record the new budgetNoPooler, read replica or database split
  5. Watch the dashboard after the change

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

Hold time is checked before size; the budget is checked before approval.

6When Demand Really Grows

Sometimes the evidence shows healthy hold times and real growth. Then the answer is capacity, chosen deliberately. A pooler such as PgBouncer in transaction mode lets many application connections share fewer database sessions, which helps when many instances each hold mostly idle connections. Read replicas take read-only traffic away from the primary. And when one database serves many unrelated domains, splitting it by ownership gives each team its own capacity and its own limits, which is usually the long-term fix for a shared database.

Whatever we choose, we write it into the platform guidelines with the reasoning, so that the next team with timeouts finds the path: evidence first, hold time second, budget third, capacity last.

7Follow-up questions

Won't a strict budget slow teams down?

It can if it becomes a ticket queue. The goal is to make the right decision quick: the dashboard and the evidence rule mean most requests are answered in minutes, either with a clear hold-time fix or a quick approval within the unallocated budget. The owner's job is to keep enough headroom and review allocations as services grow, not to say no.

How do you find the services that hold connections too long?

Look at HikariCP's usage time metric per service and at the database's sessions that are idle in transaction, grouped by application name. A service whose connections are often idle in transaction is holding connections while doing something else, usually a remote call or in-memory processing. Tracing that shows a database span with a long gap and an HTTP span inside it points straight at the code.

8Conclusion

In this answer, we saw why raising pool sizes on a shared database starts a feedback loop: past the database's capacity, more connections make every query slower, which causes more timeouts. The policy breaks that loop by making connections a budget with an owner, requiring metrics before any increase, and fixing hold time first, especially long transactions, remote calls inside transactions and Open Session in View. Standard dashboards and saturation alerts make the evidence easy to see, and real growth is handled with a pooler, replicas or a database split rather than bigger pools.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by making connections a budgeted shared resource. The database team owns the budget: they state what the database can serve, keep a reserve for admin and migrations, and allocate the rest per service, which the team divides by its maximum instance count.

Then, if they want more

Then I would add an evidence rule: any pool increase comes with HikariCP metrics, meaning active, pending, acquire time and hold time at peak. Little's law usually shows the real problem. A service at 300 requests per second with 30 milliseconds of hold time needs about 9 connections, so if it saturates 20, something is holding connections far too long.

The usual causes are long transactions, remote calls made inside a transaction and Open Session in View, which is on by default in Spring Boot. Fixing those cuts the need much more than any pool change.

For tooling, I would ship a standard dashboard per service through our platform starter, set the application name on every connection so the database's view is readable, and alert on pending connections and on total connections near the limit.

If demand really grows, I would add PgBouncer, move reads to replicas, or split the database by ownership, rather than letting pools creep up.

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 documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
java.sql, package documentation
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 "Teams keep raising database pool sizes to fix timeouts, and the shared database's...": https://scrivio-interview-library.netlify.app/databases/jdbc/b00b2d34da/