HikariCP Connection Pool — Configuration and Tuning in Spring Boot
Fast recall
Quick revision
Core answer
maximumPoolSize), `connectionTimeout` (default 30s), `maxLifetime` (30 min), `idleTimeout` (10 min), and `leakDetectionThreshold` (off by default). The counter-intuitive truth: more connections does not mean more throughput — the HikariCP formula is `(2 x cores) + effective spindles`. Oversizing causes database CPU context switching and lock contention; undersizing causes request queuing. Diagnose pool exhaustion with Micrometer metrics (hikaricp.connections.active, pending, usage), enable leakDetectionThreshold temporarily to catch leaks, and shrink long @Transactional scopes that hold connections during HTTP / I/O calls.Whether the candidate understands connection pool sizing and its impact on application performance
Setting `maximumPoolSize` to 100 thinking more connections means better performance — database servers perform worse with many concurrent connections due to CPU context switching and lock contention
Mention the formula `connections = (2 * CPU cores) + disk spindles`, explain leak detection with `leakDetectionThreshold`, and discuss how `@Transactional` scope affects connection hold time
Interview-ready guide
Interview answer
HikariCP is Spring Boot's default connection pool — chosen for low overhead and consistent throughput. Misconfiguring pool size is one of the most common sources of database performance problems.
Pool size — the counter-intuitive formula:
- More connections != better performance
- Each connection requires a thread on the DB server; too many connections increase CPU context switching
- HikariCP's recommended formula:
(2 x CPU cores) + effective spindle count - For a 4-core server with SSD storage: ~9 connections
Key timeouts:
connectionTimeout(30s default) — how long a thread waits for an available connectionmaxLifetime(30 min default) — maximum age before HikariCP recycles a connectionidleTimeout(10 min default) — how long idle connections sit before being closed down tominimumIdle
Diagnosing problems:
leakDetectionThreshold=2000— logs stack trace for connections held > 2 seconds- Expose HikariCP metrics via Actuator/Micrometer:
hikaricp.connections.active,pending— alert when pending spikes - Look for long
@Transactionalmethods that make HTTP calls; move I/O outside the transaction
HikariCP Connection Pool — Configuration and Tuning in Spring Boot
Direct Answer
HikariCP is Spring Boot's default JDBC connection pool. It maintains a pool of reusable connections to avoid the overhead of creating one per request. Key settings: maximumPoolSize (default 10), minimumIdle (defaults to maximumPoolSize), connectionTimeout (default 30s), maxLifetime (30 min), idleTimeout (10 min), and leakDetectionThreshold (off by default). The counter-intuitive truth: more connections does not mean more throughput — the HikariCP formula is (2 x cores) + effective spindles. Oversizing causes database CPU context switching and lock contention; undersizing causes request queuing. Diagnose pool exhaustion with Micrometer metrics (hikaricp.connections.active, pending, usage), enable leakDetectionThreshold temporarily to catch leaks, and shrink long @Transactional scopes that hold connections during HTTP / I/O calls.
Common Mistakes & Pitfalls
Setting maximumPoolSize to 100 thinking more connections means better performance — database servers perform worse with many concurrent connections due to CPU context switching and lock contention
Check your understanding
Answer these without looking back at the article.
- What happens if `maxLifetime` is longer than the database's connection idle timeout?
- How do you debug a `SQLTransientConnectionException: Connection is not available` in production?
- Why is calling an external HTTP API inside a `@Transactional` method a problem for the connection pool?
- How does `@Transactional(readOnly = true)` interact with HikariCP and replica routing?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.