Step 1 · The pattern
Borrow a connection, give it back
The app keeps a small pool of open database connections. Each request borrows one, runs its query and returns it. Fast queries mean a connection is free almost immediately.
- request
- served
In short
Connection pool exhaustion: how it works and how it breaks
Opening a database connection is expensive, so applications keep a fixed-size pool of open connections and lend one to each request for as long as its query runs. The pool is small on purpose: the database can only do so much at once. That makes connections the scarce resource. If a few requests hold theirs for a long time, because of a slow report, a transaction left open across a network call, or code that never gives the connection back, the pool empties. Every other request, however quick, waits for a connection and eventually times out. The confusing part is that the database looks healthy: low CPU, few active queries. The limit that was hit is in the app. Put a timeout on every statement and on waiting for a connection, keep transactions short, send slow work to a separate pool, and alert on pool wait time.
In Spring Boot
HikariCP pool size, wait time and leak detection
# Spring Boot's default pool is HikariCP
spring.datasource.hikari.maximum-pool-size=10
# how long a request waits for a connection (HikariCP default: 30000 ms)
spring.datasource.hikari.connection-timeout=2000
# log a warning when a connection is out of the pool this long (default 0 = off)
spring.datasource.hikari.leak-detection-threshold=5000The pool holds at most 10 connections, which is also HikariCP's default. A request that cannot get one within 2 seconds fails with an SQLException instead of queueing for the default 30. A connection kept out of the pool for more than 5 seconds is logged as a possible leak.
Gotcha: Leak detection only logs; it does not take the connection back, and HikariCP ignores thresholds under 2000 ms. A bigger pool is rarely the fix: the total across all instances has to fit the database's own limit. A transaction keeps its connection until it ends, so a slow HTTP call inside a @Transactional method holds one the whole time.
Names checked against the official docs on 15 Nov 2026:
How this comes up in interviews
"Requests are timing out, yet the database shows low CPU and few active queries. Where do you look, and what do you suspect?"
Then they ask
- Someone suggests making the pool a hundred times larger. Why is that risky?
- Which timeouts would you set, and where?
- A report legitimately takes a long time. How do you stop it starving fast requests?
A strong answer covers
- The pool is small on purpose, so connections are the scarce resource.
- A few requests that hold connections for a long time empty the pool, and quick requests wait and time out.
- The database looks healthy because the limit that was hit is in the app.
- Put a timeout on every statement and on waiting for a connection, and keep transactions short.
- Send slow work to a separate pool and alert on pool wait time.
Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.
On one page: the track cheat sheet.
Sources: Buttondown: incident write-up on connection limits ↗ · PostgreSQL documentation: connections and client defaults ↗ · Val Town: post-mortem on an exhausted connection pool ↗ · Report a problem
Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.