Databases

What is Connection Pool?

Definition

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

A web application serving 1,000 requests per minute queries a PostgreSQL database on each request. Without a pool, the application opens and closes 1,000 database sessions per minute, each requiring a TCP handshake and password authentication. That adds roughly 20 ms of overhead per request. With a connection pool (e.g., HikariCP configured with max connections = 10), only 10 connections are ever opened. Each request borrows an already-authenticated connection, runs the query in under 1 ms of overhead, and returns the connection to the pool. Total database handshake cost drops from 20 seconds per minute to a one-time cost of about 200 ms.

Related terms

Database connection Connection string DSN (Data Source Name) Thread pool PGBouncer HikariCP

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.

Who Is Online

In total there are 64 users online: 0 registered, 56 guests and 8 bots.

Most users ever online was 5,555 on 17 Jul 2026, 3:23 am.

Bots: AhrefsBot Applebot Baiduspider Bingbot Other Bot Other Crawler PetalBot SemrushBot

Users active in the past 15 minutes. Total registered members: 369