HardπŸ‘€ 8-15 years 1 min read

What causes database connection-pool exhaustion, and how do you fix it?

Asked inAmazonMicrosoftDeloitteWipro
#connection pool#hikaricp#leak#timeout#production
Report issue

⚑ 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

Causes→leaks, long txns, slow queries, blocking calls
Symptom→pool timeout waiting for a connection
Fix→close (try-with-resources), short txns, size pool

πŸ”₯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:

βœ“ hold-time/leak causesβœ“ timeout symptomβœ“ don't just enlarge poolβœ“ try-with-resources + leak detectionβœ“ no remote calls inside txn

⚠️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

HikariCPtry-with-resourcesSpring @Transactional

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?

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.

Related Questions