# Connection Pooling

URL: https://eoxlabs.dev/glossary/connection-pooling
Last updated: 2026-11-26
Publisher: EOXLABS (https://eoxlabs.dev)

Section: [Glossary](https://eoxlabs.dev/glossary)

Connection pooling is the practice of keeping a set of open database connections and lending them to clients as needed, instead of opening a new connection for every request. A pooler such as PgBouncer sits between the application and Postgres and carries many client connections over a smaller number of real database connections.

## Why does pooling matter for serverless and edge code?

Postgres connections are expensive. Neon's guide to [connection pooling](https://neon.com/docs/connect/connection-pooling) explains that "each Postgres connection creates a new process in the operating system, consuming memory and CPU resources," and that Postgres limits the number of connections based on available memory. Serverless code tends to open a connection per invocation, so a traffic spike becomes a connection spike, and the database starts refusing clients. Neon's pooled endpoint, which runs PgBouncer, accepts up to 10,000 client connections and funnels them into a much smaller set of real ones.

Distance adds a second cost. Cloudflare's [Hyperdrive documentation](https://developers.cloudflare.com/hyperdrive/concepts/connection-pooling/) notes that it "maintains a pool of connections to your database" placed to minimize latency, and that its pooler "operates in transaction mode". Cloudflare also notes that setting up a new connection "may require multiple round trips to the database", so pooling also removes a common cause of slow first requests, the database side of a cold start.

## What are the pooling modes?

[PgBouncer's feature list](https://www.pgbouncer.org/features.html) defines three modes, and the choice changes what application code may do:

- **Session pooling:** a server connection is assigned to a client for as long as it stays connected. "This mode supports all PostgreSQL features."
- **Transaction pooling:** a server connection is assigned "only during a transaction". This mode "breaks a few session-based features of PostgreSQL."
- **Statement pooling:** transaction pooling in which multi-statement transactions are not allowed.

## How does EOXLABS use connection pooling?

Workers that query Postgres go through Hyperdrive or Neon's pooled endpoint, both in transaction mode. Work that depends on a session, such as schema migrations, `LISTEN`/`NOTIFY` or session-level advisory locks, uses a direct connection instead. Settings that must apply to a query are made with `SET LOCAL` inside a transaction, so they cannot leak. Both services sit in the EOXLABS stack, on the [Hyperdrive](https://eoxlabs.dev/stack/hyperdrive) and [Neon Postgres](https://eoxlabs.dev/stack/neon-postgres) pages.

## Why do two transaction-mode poolers behave differently?

Transaction mode is not one behavior. Neon warns that "PgBouncer doesn't reset a server connection when it returns to the pool in transaction mode", so a plain `SET search_path` can carry over to another client's queries. Hyperdrive documents the opposite: "When a connection is returned to the pool, the connection is `RESET`", so a `SET` does not reach later queries. Code that relies on either behavior is fragile; `SET LOCAL` works the same under both.

## What is connection pooling confused with?

- **An in-process pool.** A pool held in a Worker's memory belongs to one isolate. Other isolates cannot share it, which is why pooling for edge code lives in a service in front of the database.
- **A bigger pool is faster.** Hyperdrive advises to "start conservatively" and to keep the total connection count within the database's limit across every configuration.
- **Query caching.** Hyperdrive can also cache query results. That is a separate feature with its own freshness trade-offs.

More database terms are in the [glossary](https://eoxlabs.dev/glossary).

## Related

- [Hyperdrive](https://eoxlabs.dev/stack/hyperdrive): Hyperdrive lets edge code query a central Postgres without a new connection per request, and EOXLABS splits cached and fresh reads and keeps transactions short.
- [Postgres on Neon](https://eoxlabs.dev/stack/neon-postgres): When EOXLABS chooses Postgres on Neon, how Workers connect to it, how branches change delivery, what scale to zero costs, and how it compares with D1 and Turso.
- [Cold Start](https://eoxlabs.dev/glossary/cold-start): A cold start is the extra delay when a serverless platform has to load and initialize a fresh copy of a function. It lands in the slowest requests, which is why it matters.
- [V8 Isolate](https://eoxlabs.dev/glossary/v8-isolate): A V8 isolate is a separate instance of the V8 engine with its own heap. Cloudflare Workers runs hundreds or thousands of them in one process instead of one container per program.

## More glossary

- [Eventual Consistency](https://eoxlabs.dev/glossary/eventual-consistency)
- [PHI (Protected Health Information)](https://eoxlabs.dev/glossary/phi)
- [Business Associate Agreement (BAA)](https://eoxlabs.dev/glossary/business-associate-agreement)
