pgBouncer is a lightweight connection pooler that operates in front of PostgreSQL. PostgreSQL has a process-based architecture in which one process is created per connection, and each connection consumes about 5-10MB of memory. pgBouncer solves this problem.
Pooling modes: (1) Session mode - keeps the connection for the duration of the client session, highest compatibility, (2) Transaction mode - shares connections per transaction, most efficient and recommended, (3) Statement mode - shares per statement, limited use because multi-statement transactions are not possible.
How it works: Clients connect to pgBouncer (default port 6432), and pgBouncer internally manages the PostgreSQL connection pool. In Transaction mode, when a transaction ends, the connection is returned to the pool and reused by other clients.
Performance effect: 10,000 concurrent client connections can be handled with 50 actual DB connections. It is especially effective in serverless environments (AWS Lambda, Vercel) where connections are frequently created/released. It eliminates connection creation overhead (TCP handshake, authentication).
PostgreSQL-based cloud services such as Supabase, Neon, and Railway provide pgBouncer by default, and it has become an essential component in serverless environments.