Connection Pooling
ELI5 - The Vibe Check
Opening a new database connection is expensive, like calling a new person into a meeting room every single time you need one quick question answered. Connection pooling keeps a stack of already-open connections on standby and hands them out on demand, so your app reuses the same warm connections instead of paying the setup cost over and over.
Real Talk
Connection pooling maintains a pool of pre-established database connections that application processes borrow and return instead of opening and closing a new connection per request. It reduces connection setup overhead and, more importantly, caps the total number of concurrent connections a database has to handle, which matters because databases like Postgres struggle past a few hundred direct connections.
Show Me The Code
// pg-pool config
const pool = new Pool({ max: 20, idleTimeoutMillis: 30000 });
When You'll Hear This
"Serverless functions need external connection pooling or they'll exhaust Postgres." / "We put PgBouncer in front of the database to handle pooling at scale."
Related Terms
PgBouncer
PgBouncer is a lightweight connection pooler that sits in front of PostgreSQL and recycles database connections like a good environmentalist.
PostgreSQL
PostgreSQL (just say 'Postgres') is the Swiss Army knife of databases.
Read Replica
A read replica is a copy of your database that only handles read queries.
Transaction
A transaction groups multiple database operations into one all-or-nothing bundle. Either ALL of them succeed, or NONE of them happen.