HardExperience level: 8-15 years1 min read

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

Reviewed by Gurusankar M.

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.

On this page

Concept Made Simple

Coffee Chat Question

β€œWhat causes database connection-pool exhaustion, and how do you fix it?”

Remember It Faster

Mind Map Answer

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

Think Beyond the Expected

What If?

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

  1. Why can a bigger pool make things worse?
  2. How does HikariCP leakDetectionThreshold help?
  3. Why is calling an API inside a DB transaction dangerous?

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?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.