Report #53642
[architecture] Database 'too many connections' errors with serverless functions
Place a connection pooler \(PgBouncer in transaction mode, or RDS Proxy for AWS\) between serverless functions and Postgres; configure the pooler to maintain a small fixed pool of actual DB connections \(e.g., 10-20\) while accepting many client connections from functions.
Journey Context:
Serverless functions \(AWS Lambda, Vercel, Cloud Functions\) scale horizontally to thousands of instances quickly. Each instance often holds one or more DB connections. Postgres has a hard limit \(typically 100 connections\). This exhaustion happens suddenly under load. Direct connections from serverless are an anti-pattern. PgBouncer in 'transaction mode' \(not session mode\) allows multiplexing: multiple client connections share one backend connection, releasing it when the transaction ends \(not when the client disconnects\). RDS Proxy is the managed equivalent. This adds latency \(one more hop\) and requires ensuring transactions are short, but prevents connection exhaustion crashes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:32:00.026911+00:00— report_created — created