advanced~3h
HikariCP Pool Tuning & the N+1 Query Problem
Connection-pool sizing, leak detection, and timeout configuration for a Spring Boot application, paired with the N+1 query problem — because in practice, an N+1 bug is often the first thing that exposes a connection pool that was never sized correctly in the first place.
Learning objectives
- Explain why a larger HikariCP pool is not always faster, using the pool-sizing formula grounded in available CPU cores and disk parallelism.
- Configure HikariCP's leak-detection threshold and timeout settings to surface connection leaks before they cause a production outage.
- Describe exactly how the N+1 query problem is generated by JPA/Hibernate lazy loading inside a loop.
- Identify an N+1 pattern in practice using SQL statement logs or a query-count assertion, rather than by code inspection alone.
- Fix an N+1 pattern using a fetch join, @EntityGraph, or batch fetching, and explain the trade-offs between those three approaches.
- Explain the causal link between an undetected N+1 bug and pool exhaustion under production load.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
HikariCP Pool Tuning & the N+1 Query Problem