System Design Patterns: From Fundamentals to Real Systems

0% completed

Database Connection Pooling

The Pattern

Opening a database connection is expensive; running a query on one is cheap. So open a handful of connections once, keep them alive, and let requests borrow and return them: the module intro's shared phone lines, kept open, instead of redialing for every call.

First, feel the cost being avoided. A new database connection is a TCP handshake, a TLS negotiation, and authentication: 20-50 ms before your first query: and on the database side it's not just time: in Postgres, each connection is a dedicated server process holding real memory

.....

.....

.....

Like the course? Get enrolled and start learning!