Best practices for handling spike demand
devWhen your application experiences sudden spikes in request volume, the configuration of your connection pool significantly impacts performance and database resource consumption.
Recommended Configuration
For the best performance in response to spike demands, HikariCP recommends using a fixed-size pool. A fixed-size pool avoids the latency penalty of establishing new connections during a spike.
The Risk of Dynamic Sizing
Using a dynamically-sized pool (e.g., setting minimumIdle to a value lower than maximumPoolSize) in an environment where connection establishment is expensive (e.g., due to DNS, encryption, or external authentication) can lead to:
- Increased Latency: New requests must wait for the connection establishment time (which can be hundreds of milliseconds).
- Connection Bloat: Other connection pools may aggressively create many new connections to satisfy a spike, whereas HikariCP uses elision logic to ensure that if a spike is transient, it only adds the minimum necessary connections to satisfy demand, preventing unnecessary resource consumption on the database server.