Prisma · sdk · fg-0583

A new PrismaClient in each route or function opens its own connection pool and runs the database out of connections under real traffic

If you see Requests fail with too many connections or connection pool timeout errors once more than a handful of people use the app, the cause and the fix for Prisma are below, last verified 2026-11-05.

Verified Nov 2026trust 50/100
Symptom
Requests fail with too many connections or connection pool timeout errors once more than a handful of people use the appThe database dashboard shows far more open connections than active users
Cause
In a serverless deployment each function instance makes its own PrismaClient, and each client keeps its own connection pool. A client created inside a route, or in every route file, multiplies those pools, and concurrent functions during a traffic spike can use up the database's connection limit quickly.
Fix
Create one PrismaClient in a shared module, outside any handler, and import it everywhere. Keep each function's pool small, and put a connection pooler (such as PgBouncer, or your host's pooled connection string) between the functions and the database.
Apply
// lib/prisma.ts import { PrismaClient } from '@prisma/client' const globalForPrisma = global as unknown as { prisma: PrismaClient } export const prisma = globalForPrisma.prisma || new PrismaClient() if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma // app/api/orders/route.ts import { prisma } from '@/lib/prisma'
Affected
Apps that use Prisma Client from serverless functions, Next.js Route Handlers, Server Actions or API Routes
Sources

Last verified 2026-11-05 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun