What is Connection Pool?
A managed cache of database connections that applications reuse rather than opening and closing a connection for each query, reducing latency and server load.
A connection pool is a software-managed collection of pre-established database connections that an application can borrow, use, and return without incurring the overhead of a full TCP handshake, TLS negotiation, or database authentication on every operation. Connection pooling is a standard pattern in most application servers, ORM frameworks, and database drivers (for example, HikariCP in the Java ecosystem, pgBouncer for PostgreSQL, or SQLAlchemy's pool in Python). Without a pool, each user request that touches the database would open a new socket, wait for the three-way handshake, authenticate against the database server, execute the query, tear down the socket, and repeat on the next request. That adds 10-50 milliseconds of latency per query before any SQL processing begins. A pool replaces that startup cost with a simple borrow-and-return cycle that takes microseconds.
The pool maintains a minimum and maximum number of connections (for example, minIdle=5, maxTotal=20). When an application asks for a connection, the pool hands back an idle one if available; if all are in use and the maximum has not been reached, the pool creates a new one. If the maximum is reached, the caller blocks (or receives a timeout error) until another thread returns a connection. The pool also validates connections: it may run a lightweight test query (e.g., SELECT 1) before handing one out to ensure the database has not closed the idle socket. Stale connections, common after a database restart or a firewall timeout, are evicted transparently.
At the infrastructure level, a connection pool sits directly between the application and the database server, often on the same host as the application. It is a critical performance tuning knob: too few connections causes queuing under load, too many exhausts database memory or file descriptors. Most pools support metrics such as active count, idle count, and pending requests so operators can right-size them for a given workload.
Key facts
- Avoids repeated TCP/TLS handshakes and authentication for each database query.
- Typical pool sizes range from 5 to 50 connections, tuned to database connection limits and query concurrency.
- Has minIdle (connections kept open even when idle) and maxTotal (hard limit on open sockets) parameters.
- Employs validation queries (e.g., SELECT 1) to detect and evict stale connections.
- Most application frameworks (Spring Boot, Django, Rails) include or integrate a built-in pool.
How it works in practice
Related terms
References
More in Databases
ACID
ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties guaranteeing reliable database transaction processing, ensuring data integrity despite concurrent access or failures.
B-Tree Index
A B-Tree index is a self-balancing tree data structure that maintains sorted data for efficient insertion, deletion, and range queries in database systems.
BASE
BASE is a design philosophy for distributed databases that prioritizes availability and partition tolerance over immediate consistency, making it a looser alternative to ACID in NoSQL systems.
CAP Theorem
CAP theorem states that a distributed data system cannot simultaneously provide consistency, availability, and partition tolerance; it can only guarantee two of the three.
Failover
Failover is the process of automatically or manually promoting a replica database to primary when the active node fails, ensuring continued availability.
Foreign Key
A column or set of columns in a database table whose values must match a primary key in another table, ensuring referential integrity between the two tables.
Hash Index
A data structure that maps keys to storage locations using a hash function, providing constant-time equality lookups but no ordered or range scans.
Materialized View
A database object that stores the precomputed result of a query as a table, refreshed periodically or on demand to improve read performance and reduce computational overhead.
NoSQL
NoSQL is a family of non-relational database systems designed for flexible schemas, horizontal scaling, and high-throughput data access that traditional SQL databases cannot easily provide.
Read Replica
A read replica is an asynchronously updated copy of a primary database instance used to offload and scale read-only query traffic without affecting the source database's write performance.