Why Do We Need DB Connection Pools?
Typical data-driven web apps need a Database (DB) connection to render almost every page or to serve every API call. For scalability reasons, Web Server and Database servers are hosted on different Machines. In such scenario, obtaining a new DB connection is a potentially expensive task. This process of acquiring a new DB connection increases the latency of your pages and makes your web app slow.
DB Connection Pools Solve This Problem
In Java web applications DB connection pools are provided as libraries. The DB connection pool manager keeps a number of DB connections open in memory. When the data access code closes a connection, the connection pool manager doesn’t close the connection, instead, it returns it to the pool. When the next call requests a connection, it returns an unused connection from the pool, rather than creating a new one. This improves the latency of your application.