Prisma + serverless: "Timed out fetching a new connection from the connection pool" — one instance, one hundred concurrent invocations
Problem
Every individual function invocation is fast in isolation. Under real traffic — a page that fires ten API calls at once, times ten users — everything times out together:
PrismaClientUnknownRequestError: Timed out fetching a new connection from the connection pool.
(More info: http://pris.ly/d/connection-pool, Current connection pool: 10, Max: 10)And the database side tells the other half of the story: a connection count graph that spikes straight past the provider's ceiling whenever traffic rises.
Root cause
This is not the classic "your app pool is too small" problem — it is the serverless amplification of it. Each warm function instance holds its own Prisma pool (default connection_limit = num_cpus × 2 + 1, effectively ~10). One hundred concurrent invocations means up to 100 instances × 10 connections each = a thousand Postgres connections, against a database that accepts a fraction of that. The requests queue inside each instance's pool waiting for connections the database cannot grant, and the pool fetch times out — which is the error above.
Raising connection_limit down or up inside the function changes almost nothing; the multiplication across instances is the problem. The fixes operate on the multiplication.
# DATABASE_URL for serverless + PgBouncer in transaction mode
… 1 more line in the fix🔒 the fix — including 3 code blocks — is members-only. $1/mo unlocks everything.