Rule
Database connection pools must be sized based on measured concurrency with bounded timeout on acquire.
Why
Unbounded pools or no acquire timeout causes database overload and cascading failure under traffic spikes.
Must
- Set a maximum pool size informed by the database max_connections limit.
- Set an acquire timeout to fast-fail rather than queue indefinitely.
- Set a query timeout at the connection level as a last-resort safety net.
- Test with connection at max and verify graceful degradation.
Should
- Set minimum idle connections to remove cold-start latency.
- Monitor pool utilization and alert at 80% sustained usage.
Anti-patterns
- Pool max set to unlimited.
- No acquire timeout, causing requests to hang indefinitely.
- Creating a new connection per request outside the pool.
Test Cases
- Saturated pool returns 503 within the acquire timeout window.
- Pool recovers automatically after a connection spike.
Telemetry
- pool_utilization_percent
- pool_acquire_timeout_errors
- pool_acquire_latency_p99