{"success":true,"name":"database-connection-pools-are-finite-size-release-and-watch-","description":"Backend talks to a database and traffic or serverless scaling is growing","category":"ai-brimind","path":"ai-brimind/database-connection-pools-are-finite-size-release-and-watch-/SKILL.md","file":"SKILL.md","content":"---\nname: database-connection-pools-are-finite-size-release-and-watch-\ndescription: \"Backend talks to a database and traffic or serverless scaling is growing\"\n---\n\n# Database Connection Pools Are Finite: Size, Release, and Watch for Exhaustion\n\n## When to use\nA backend (Node/Next.js or similar) opens database connections, and nobody has consciously set pool size, release discipline, or checked the DB's connection ceiling.\n\n## Example request\nApp hangs under load with no error → every pool connection is checked out and requests queue forever; the pool was silently exhausted. — A code path grabs a connection and returns early on error without releasing → the pool leaks one connection per failure until nothing works; every checkout needs a guaranteed release. — Serverless functions each open their own pool → 200 cold starts multiply into more connections than the DB allows; a shared/cached connection or a pooling proxy is the known mechanism. — Pool size raised to 500 to 'fix' slowness → the DB itself drowns; the pool exists to protect the database, not to be unlimited.\n\n## Instructions\nAct as a librarian managing a small set of shared keys: every key handed out must come back, and there are fewer keys than people. When a backend uses a database: 1) Find the real numbers first — the database's maximum connections, the pool size your client defaults to, and how many app instances multiply that pool; the product of instances times pool size must stay under the DB's ceiling with room to spare. 2) Audit release discipline: every path that acquires a connection — including error paths and early returns — must guarantee release; use the client's built-in patterns that release automatically rather than manual pairing. 3) In serverless or hot-reload environments, cache one client/pool per process instead of creating one per request or per reload — reconnection storms are a known trap with a known caching fix. 4) Make exhaustion visible: set an acquire timeout so a starved request fails loudly with a clear error instead of hanging forever, and watch pool metrics if the client exposes them. 5) When the pool runs dry, diagnose before resizing: leaked connections, slow queries hogging checkouts, or genuine load are three different diseases; a bigger pool only treats the third. If you don't know the current numbers, measure them before changing configuration. Only tune once the exhaustion cause is confirmed, and explain why the change fixes the actual leak or bottleneck instead of postponing the same hang to a bigger number.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #968\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}