Chapter 15: Performance and cost

Some limits don't show up in any profile, because the code is simply waiting its turn for something.

Connection pool

A fixed set of open database connections that requests borrow and hand back. Opening a new one each time is slow, so they are reused. If all are in use, a request waits. If code forgets to hand one back, the pool slowly runs out.

This one bites agents because everything works in development, where there is one user. A missing release only shows up under load. A pool per serverless instance can multiply past what the database allows. And the instinct to fix it with a bigger pool can make it worse.

Say it to your agent

“Use one shared pool from src/db/pool.ts with max: 10, and release in a finally block on every path. Then run k6 at 100 requests per second for 2 minutes against staging and show me pool wait time and any connection errors. Don't raise max to fix an error until we know why it happened.”

The workshop

Name a word, or describe what you mean in everyday language.