Architectural Breakdown & AnalysisFAANG Aligned
Opening a new database TCP connection per request takes 30-100ms. Connection pools maintain pre-allocated database connections for instant reuse.
Pool Sizing Mechanics
Counterintuitively, smaller connection pools often yield better performance than massive pools due to reduced CPU context switching and disk lock contention.
PostgreSQL Recommended Formula
connections = (CPU_cores * 2) + effective_spindle_count
yaml
# HikariCP Configuration
maximumPoolSize: 10
minimumIdle: 10
idleTimeout: 600000
connectionTimeout: 30000TIP — Connection Starvation
Set connectionTimeout (e.g., 30s) so caller threads fail fast with clear errors instead of hanging indefinitely when pools are exhausted.
Key Architectural Comparison
| Connection Model | Memory Footprint on DB Master | Connection Setup Latency | Throughput Under 10k Threads |
|---|---|---|---|
| Connection-per-Request | Catastrophic (PostgreSQL forks process per socket). | 30–100ms TLS/Auth handshake per query. | DB engine crashes due to thread thrashing. |
| HikariCP Connection Pool | Fixed bounded memory (e.g. 50 connections). | Sub-millisecond (Reuses pre-warmed open sockets). | Optimal (Eliminates CPU context-switch overhead). |