Spring Boot Interview Question: Connection Pool Exhaustion
Connection pool, exhaustion, coding , concept and more ...
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 )
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
@Asyncon blocking JDBC operationsUse batch updates for bulk writes




