Engineering With Java

Engineering With Java

Spring Boot Interview Question: Connection Pool Exhaustion

Connection pool, exhaustion, coding , concept and more ...

Suraj Mishra's avatar
Suraj Mishra
Feb 13, 2026
∙ Paid

Scenario

You are working on a Spring Boot–based User Activity Service for a high-traffic SaaS application.

Every time a user logs in, the system updates the last_login timestamp in a PostgreSQL database.

During peak hours, production starts showing:

  • Requests stuck waiting for database connections

  • HikariCP pool exhaustion errors

  • Sudden spike in API latency

  • No obvious slow SQL queries

After investigation, the following code is found.

What are the problems with the implementation? How would they contribute to connection pool exhaustion.

For updateUsers method:

@Transactional borrows a JDBC connection at the start of the method and returns it only after the method completes.

transaction wraps:

  • Multiple database updates

  • Slow, non-database processing (Thread.sleep)

This causes a single connection to be held for several seconds.

Under load, active connections increase faster than they are released, exhausting the pool.

for ayncUpdate() method:

@Async + @Transactional Is a Hidden Trap

Each async thread:

  • Starts its own transaction

  • Borrows a database connection

  • Blocks until JDBC work finishes

Async threads can scale independently, but database connections cannot.

This quickly overwhelms the connection pool.


📢 Get actionable Java/Spring Boot insights every week — from practical code tips to real-world use-case based interview questions.

Join 5000+ subscribers and level up your Spring & backend skills with hand-crafted content — no fluff.

First 100 paid subscribers will get the annual membership at $50/year ( 60 already converted to paid, 40 remaining )

So far we have covered 44+ real world based interview questions and will add up to 100 by end of this year.

Subscribe

Not convinced? Check out the details of the past work


How would you fix this?

Key Principles:

  • Keep transactions short and deterministic

  • Never mix slow logic with database transactions

  • Avoid @Async on blocking JDBC operations

  • Use batch updates for bulk writes

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2026 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture