Performancepoolingpgbouncerdatabase proxy

Connection pool

Definition

A connection pool keeps a bounded number of established connections; a request borrows one, uses it and returns it, waiting in line if all are busy.

In practice

Opening a database connection costs network round trips, TLS, authentication and, in PostgreSQL, a whole server process, often several milliseconds and megabytes each. Pools remove that cost from the request path and cap how many connections the database sees. Pool wait time is real queueing delay and shows up in latency, then as pool timeouts once demand exceeds capacity.

Bigger is not better: a database runs best with a small number of active connections, roughly proportional to its cores, and more cause contention. Pools multiply with scale-out: 50 instances with 20 connections each means 1,000 connections. Serverless functions make it worse, which is why external poolers such as PgBouncer or a managed database proxy sit in front.

Example

Each app instance keeps a pool of 10 connections to a PostgreSQL server with max_connections=200; scaling from 15 to 30 instances needs 300 and fails until PgBouncer multiplexes them onto 40 server connections.