Skip to main content
networking

Connection Pooling

Connection pooling maintains a cache of pre-established database or HTTP connections that are reused across requests instead of creating new ones. Eliminates TCP handshake + TLS negotiation overhead per request. Critical for performance – a PostgreSQL connection takes ~100ms to establish but <1ms to reuse from pool.

Definition

Connection pooling amortizes the cost of connection establishment across many operations. Database connections are expensive to create: TCP handshake (1 RTT), TLS negotiation (1-2 RTT), authentication (protocol-specific), and server-side memory allocation. A connection pool maintains N idle connections ready for immediate use. When a request needs a database connection, it borrows one from the pool (microseconds), uses it, and returns it. Configuration parameters: min idle (connections kept warm), max active (hard ceiling), max wait (timeout when pool exhausted), idle timeout (close stale connections), and validation query (detect broken connections). PgBouncer (PostgreSQL), ProxySQL (MySQL), and HikariCP (Java) are dedicated connection poolers. HTTP connection pooling (keep-alive) reuses TCP+TLS connections for multiple requests – critical for API clients making repeated calls to the same host.

Examples

  • PgBouncer: pool_mode = transaction; max_client_conn = 1000; default_pool_size = 20
  • HikariCP: maximumPoolSize=10, minimumIdle=5, connectionTimeout=30000
  • Python requests.Session() reuses HTTP connections via urllib3 pool

Related Protocols

Related Terms