System Design Patterns: From Fundamentals to Real Systems
Vote
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.
First, understand the cost being avoided. A new database connection is a TCP handshake, a TLS negotiation, and authentication. That is 20-50 ms before your first query. On the database side it is not just time. In Postgres, each connection is a dedicated server process holding real memory. Meanwhile the query you wanted to run takes 5 ms
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%