What causes database connection-pool exhaustion, and how do you fix it?
β‘ Short Answer
The pool runs out when connections are held too long (slow queries, long transactions, external calls inside a txn) or leaked (not closed). Symptoms: 'connection timeout' waits. Fix: right-size the pool, shorten transactions, never call remote services while holding a connection, and use try-with-resources + leak detection.
βCoffee Chat Question
Concept Made Simple
βWhat causes database connection-pool exhaustion, and how do you fix it?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
Is the fix usually to just increase the pool size?
Rarely. A bigger pool can overwhelm the DB (each connection costs DB memory/CPU) and only masks the real issue: connections held too long. Fix the holding time (slow queries, transactions spanning HTTP calls, leaks) first; size the pool to the DB's capacity.
πReal World
HikariCP timeouts under load almost always trace to leaked connections or transactions that wrap a slow downstream call; the durable fix is reducing hold time, not inflating the pool.
π―Interviewer's Expectation
Keywords they're listening for:
β οΈCommon Mistakes
- βIncreasing pool size as the first fix
- βHolding a connection across external/HTTP calls
- βLeaking connections (no try-with-resources)
β Best Practices
- βAcquire connections in try-with-resources
- βKeep transactions short; no remote calls inside
- βSize the pool to DB capacity; enable leak detection
πFollow-up Questions
- 1Why can a bigger pool make things worse?
- 2How does HikariCP leakDetectionThreshold help?
- 3Why is calling an API inside a DB transaction dangerous?
π§©Related Technologies
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Optimization (SQL) Interview question: "What causes database connection-pool exhaustion, and how do you fix it?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.