Efficiently manage database connection pools with Fluid compute

How to create high-performance database connection pools without leaking connections

2 min read
Last updated November 24, 2025

Establishing a database connection is expensive—requiring TCP handshakes, authentication, and resource allocation that can take 50-100ms or more. Without connection pooling, applications create and destroy connections for every request, wasting resources and overwhelming databases until they hit connection limits and crash under load.

Connection pooling maintains a ready pool of reusable connections, eliminating this overhead and enabling applications to scale efficiently under real-world traffic. Requests to your database become faster since your application can use an existing connection instead of creating a new one.

However, managing the behavior of database connection pools so that they both reuse connections and don’t leak can be difficult in serverless environments. On Vercel’s Fluid compute, connection pools are much easier to manage.

Fluid compute offers a blend of serverless flexibility and server-like capabilities. Unlike traditional serverless architectures, which can face issues such as cold starts and limited functionalities, fluid compute provides a hybrid solution. It overcomes the limitations of both serverless and server-based approaches, delivering the advantages of both worlds,

Additionally, Fluid compute is billed using Active CPU pricing, meaning you only pay for the compute that you use. When your backend is waiting on I/O like database queries, AI model calls, and other external services.

To pool connections with Fluid compute on Vercel, use the attachDatabasePool function from @vercel/functions:

import { Pool } from "pg";
import { attachDatabasePool } from "@vercel/functions"
const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});
attachDatabasePool(pool);
export default {
async fetch() {
const client = await pool.connect();
try {
const result = await client.query('SELECT NOW()');
return Response.json(result.rows[0]);
} finally {
client.release();
}
},
};

attachDatabasePool will automatically manage pooling for supported database clients, including PostgresQL (pg), MySQL2, MariaDB, MongoDB, Redis (ioredis), Cassandra (cassandra-driver), and more.

Was this helpful?

supported.