Can Netlify Functions share a database connection pool across concurrent invocations?
0 reputation · 14 Oct 2025, 11:46 UTC
I'm deploying a Netlify Function (Node.js runtime) that queries a PostgreSQL database. Under normal traffic everything works, but during bursts the database intermittently rejects new connections once its max_connections limit is reached, even though the function itself scales fine.
My understanding is that each Netlify Function invocation may run in a fresh execution environment, so a module-level pool created by a standard ORM or driver (e.g., pg.Pool) is only reused within a single warm instance and is discarded when the instance is recycled. That would mean concurrency, not my pool size setting, drives the real connection count.
Before rearchitecting, I want to confirm the expected behavior and the right diagnostic approach:
- Does Netlify make any guarantee about connection reuse across concurrent or sequential function invocations, or should every invocation be treated as potentially opening new connections?
- Is a per-invocation connection (open, query, close) the recommended pattern, or is an external pooler such as PgBouncer the intended solution for relational databases behind Netlify Functions?
- What is the most practical way to verify the cause — comparing concurrent function executions against the database's active connection count during a load test?
Assume current Netlify Functions behavior as of 2026; if the platform has changed its concurrency or reuse model recently, please flag that for verification.