Why this matters
- Connection pool exhaustion is a top production failure mode — every request waiting for a connection times out simultaneously.
- Pool sizing directly affects throughput and database load — too few connections starve requests, too many overwhelm the database.
- HikariCP is the fastest pool available for Java; Boot configures it automatically when a DataSource starter is present.
Connection pool role
L1 · FresherHikariCP reuses JDBC connections — creating a connection per request would exhaust database resources.
Key settings
L2 · Intermediatemaximum-pool-size, connection-timeout, and idle-timeout live under spring.datasource.hikari.*.
Pool sizing math
L3 · AdvancedRough guide: pool size ≈ threads that hit the DB concurrently — not equal to total Tomcat threads.
Leak detection
L4 · ExpertEnable leak detection thresholds in staging; log long-held connections tied to missing @Transactional boundaries.
Cache-aside with ElastiCache
Default configuration
Boot auto-configures HikariCP with sensible defaults:
spring:
datasource:
url: jdbc:postgresql://127.0.0.1:5432/bookstore
username: bookstore
password: ${DB_PASSWORD}
hikari:
maximum-pool-size: 10
minimum-idle: 5
connection-timeout: 30000
idle-timeout: 600000
max-lifetime: 1800000
pool-name: BookStorePool
No extra dependency needed — spring-boot-starter-data-jpa includes HikariCP.
Key HikariCP settings
maximum-pool-size— Maximum concurrent connections. Default 10.minimum-idle— Connections kept warm when idle. Default equals max pool size.connection-timeout— Milliseconds to wait for a connection before throwing exception. Default 30s.idle-timeout— How long an idle connection stays in the pool. Default 10 minutes.max-lifetime— Maximum age of a connection before retirement. Default 30 minutes.
Pool sizing formula
A widely used guideline:
connections = (core_count * 2) + effective_spindle_count
For a BookStore API on a 4-core server with SSD:
connections = (4 * 2) + 1 = 9
Set maximum-pool-size: 10. Adjust based on monitoring, not theory.
Critical rule: Total connections across all app instances must not exceed the database's max_connections. With 3 BookStore pods at 10 connections each, you need at least 30 available on PostgreSQL.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 5 sections
- Monitoring pool health
- Connection leak detection
- Tuning for BookStore workloads
- Read replicas
- Validating connections
Test yourself
Answer these before moving on — recall is what makes it stick.