Skip to content
Dashboard

The real serverless compute to database connection problem, solved

CTO, Vercel

Link to headingYou can stop reading now if

Link to headingThe ground truth

Link to headingThe real problem

A pool client idle time should fire while the function is suspended, but it never does because the function is suspended. This “leaks” the pool client.A pool client idle time should fire while the function is suspended, but it never does because the function is suspended. This “leaks” the pool client.
A pool client idle time should fire while the function is suspended, but it never does because the function is suspended. This “leaks” the pool client.

Link to headingWhy suspension leaks connections

Link to headingSo, is this a real problem?

Link to headingIs there a solution?

import { Pool } from "pg";
import { attachDatabasePool } from "@vercel/functions"
const pool = new Pool({
connectionString: process.env.POSTGRES_URL,
});
attachDatabasePool(pool);

Link to headingCost implications

Link to headingBest practices

Link to headingConfigure relatively low connection idle timeouts

Link to headingDefine your connection pools globally

Link to headingDon’t set the maximum pool size to 1

Link to headingUtilize rolling releases

Link to headingSummary

Ready to deploy?