DeepReach
Spring14 interview questions

HikariCP Connection Pool Tuning for Production

Size your connection pool correctly, diagnose connection leaks, configure timeouts, and monitor pool health in Spring Boot applications under BFSI load.

HikariCPConnection PoolSpring BootPerformance

HikariCP Connection Pool Tuning for Production

The Pool Size Formula

HikariCP recommends: *pool_size = (cores 2) + effective_spindle_count**

For a 4-core machine with SSD: pool_size = (4 * 2) + 1 = 9

yaml
spring:
  datasource:
    hikari:
      maximum-pool-size: 10
      minimum-idle: 5
      connection-timeout: 30000      # 30s — fail fast
      idle-timeout: 600000           # 10min
      max-lifetime: 1800000          # 30min (less than DB wait_timeout)
      keepalive-time: 30000          # prevent firewall drops
      leak-detection-threshold: 60000 # detect connection leaks

Diagnosing Connection Leaks

Enable leak detection and check logs for:

WARN  c.z.h.p.ProxyLeakTask - Connection leak detection triggered

Common causes: missing try-with-resources, exceptions bypassing close(), @Transactional on too-coarse methods.

Interview Questions

  1. 1.Why should max-lifetime be less than the database's wait_timeout?
  2. 2.What is the difference between connectionTimeout and socketTimeout?
  3. 3.How do you size a connection pool when using virtual threads?
  4. 4.What metrics should you alert on for connection pool health?