Why this matters
- Opening a Postgres connection takes 20–50ms; at 1000 RPS that overhead alone exceeds query time.
- Pool exhaustion — every connection busy, requests queue — is a classic production outage pattern.
- HikariCP is Spring Boot's default pool; misconfigured
maximumPoolSizestarves or overwhelms Postgres. - Interview system-design questions pair pool sizing with thread pool sizing and database
max_connections.
Clustered (PK)
Table rows (sorted by PK)
Row 1id=1
Row 2id=2
Row 3id=3
Non-clustered (email)
email index→ row pointer
Table heapunordered rows
Why connections are expensive
Each Postgres connection spawns a backend process consuming ~5–10 MB RAM. The handshake involves TCP, TLS, authentication, and session setup:
// Anti-pattern: new connection per request
Connection conn = DriverManager.getConnection(url, user, pass);
// ... query ...
conn.close();
VaultCommerce's early prototype did this under load — Postgres hit max_connections (100) within minutes of a marketing email blast.
How pooling works
The pool maintains warm connections. Application threads borrow, execute SQL, and return:
Pool lifecycle
- Startup — Pool opens
minimumIdleconnections. - Borrow — Thread requests connection; pool assigns idle one or waits (up to timeout).
- Use — Thread runs queries on the borrowed connection.
- Return — Connection goes back to idle queue, not closed.
- Eviction — Stale or broken connections are replaced.
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 · 3 sections
- HikariCP configuration
- Sizing formula
- Pool exhaustion symptoms
Test yourself
Answer these before moving on — recall is what makes it stick.