← all devlogs
Engineering·2026-08-28·4 MIN READ

Serverless Database Pools Without Burning Connections

A practical guide to keeping database connections under control in serverless environments — from maxIdleTimeMS to Vercel's attachDatabasePool.

Serverless and databases have a fundamental tension: functions are ephemeral, databases count connections. Here's how to make them work together.

The problem

Every cold start creates a new connection. With traffic spikes, you hit the connection limit.

The fixes in order

1. **maxIdleTimeMS**: Close idle connections fast 2. **Connection caching**: Reuse the client across invocations 3. **attachDatabasePool**: Vercel's cleanup on function suspension

const client = new MongoClient(uri, { maxIdleTimeMS: 5000 });
attachDatabasePool(client);

Monitoring

Watch connection count in your database dashboard. If it spikes with traffic, your pool isn't being reused — check if the client is module-scoped.

ServerlessDatabaseVercel