System Design Patterns: From Fundamentals to Real Systems
0% completed
Database Connection Pooling
1. The Pattern
Opening a database connection is expensive; running a query on one is cheap. So open a small number of connections once, keep them alive, and let requests borrow and return them.
Begin with the cost this pattern avoids. A new database connection requires a TCP handshake, TLS negotiation, and authentication, consuming 20-50 ms before the first query begins. The database also allocates resources because Postgres uses a dedicated process with real memory for each connection. A query that takes 5 ms should not repeatedly pay ten times that amount for setup
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%