Spring Boot + MySQL Connection Pool Tuning
Fast recall
Quick revision
Core answer
Tests practical production engineering knowledge.
Interviewers want to see that the candidate has operated Spring Boot with MySQL in production, understands the HikariCP parameters, and knows how to diagnose connection pool exhaustion.
Interviewers want to see that the candidate has operated Spring Boot with MySQL in production, understands the HikariCP parameters, and knows how to diagnose connection pool exhaustion.
Interview-ready guide
Interview answer
Spring Boot uses HikariCP as its default connection pool, and most connection pool problems in production come from two settings: maximumPoolSize and connectionTimeout.
maximumPoolSize — smaller than you think
- The common mistake is setting this to match the thread count or expected concurrent requests — but the bottleneck is the database CPU and disk, not connection slot availability
- HikariCP's own guidance:
(number of CPU cores x 2) + effective spindle count— for a 4-core MySQL server, that's roughly 9-10 connections, not 100 or 200; a pool that's too large causes connection queuing at the MySQL layer, consuming memory without improving throughput - Monitor
hikaricp_pending_threads— if threads are consistently waiting for a connection, either the pool is undersized or queries are holding connections too long
connectionTimeout — fail fast
connectionTimeoutcontrols how long a thread waits for a pool connection before throwingSQLTimeoutException— the Spring Boot default is 30 seconds, which is far too long for production; a user's HTTP request will have timed out before that- Set it to 3-5 seconds so that when the pool is exhausted, callers fail fast rather than hanging and consuming server threads
Key properties in application.properties
spring.datasource.hikari.maximum-pool-size: the upper connection limitspring.datasource.hikari.connection-timeout: milliseconds to wait for a connection (default 30000; set to 3000-5000)spring.datasource.hikari.idle-timeout: how long an idle connection can stay in the pool before being retired (default 600000ms)spring.datasource.hikari.max-lifetime: maximum connection age before rotation (default 1800000ms; prevents stale connections after MySQL'swait_timeoutcloses them)
Enable HikariCP metrics with Micrometer by adding spring-boot-starter-actuator — pool wait time, active connections, and pending threads are the metrics to monitor.
Spring Boot + MySQL Connection Pool Tuning
Direct Answer
Spring Boot defaults to HikariCP as its connection pool. Key tuning parameters are maximumPoolSize (limit concurrent connections to MySQL's thread capacity), minimumIdle (warm connections for burst traffic), connectionTimeout (fail fast instead of queuing forever), and idleTimeout. For production, align maximumPoolSize with your MySQL max_connections limit divided by the number of application instances.
Common Mistakes & Pitfalls
Interviewers want to see that the candidate has operated Spring Boot with MySQL in production, understands the HikariCP parameters, and knows how to diagnose connection pool exhaustion.
Check your understanding
Answer these without looking back at the article.
- What happens when HikariCP's connectionTimeout is exceeded — what exception is thrown and how should it be handled?
- How would you configure separate connection pools for read and write DataSources in Spring Boot?
- What is the difference between minimumIdle=0 and minimumIdle=maximumPoolSize and when would you use each?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.