The connection pool that was fine until it wasn't
A pool sized for normal traffic works for months. Then one slow query holds its connection a few seconds too long, and every other request in the app starts queueing behind it.
Hammad Iqbal
Software Engineer
Database connection pools are one of those settings you configure once during setup and never think about again — until every request in the app starts timing out at the same moment, the database itself reports client CPU as fine, and the actual bottleneck turns out to be a queue of application processes waiting for a connection that never frees up.
- A connection pool that looks correctly sized under normal load can still exhaust under a small number of slow queries.
- Symptoms show up as request timeouts across unrelated endpoints, not as a database error.
- Pool size, query timeout, and idle-connection reaping all need to be tuned together, not independently.
One slow query can starve the whole app
A pool of 20 connections handles normal traffic without issue. Then a report-generation endpoint runs a query that takes 8 seconds instead of 80 milliseconds. Multiply that by a handful of concurrent users hitting the same endpoint, and a meaningful fraction of the pool is now tied up on one slow code path — while every unrelated request, including ones that don't touch that table, waits in line for a connection to free up.
Sizing is a tradeoff, not a constant
A bigger pool delays the symptom but doesn't fix the cause, and past a point just moves the bottleneck to the database's own max-connections limit. The fix that actually holds is bounding how long any single query is allowed to occupy a connection, and giving slow, infrequent queries a separate pool so they can't queue out the fast, frequent ones.
If unrelated endpoints start timing out together, check the connection pool before the code — a shared resource turns one slow query into an outage for everyone.
Have a project this kind of thinking applies to?
Tell me what you're building — I read every message myself.