Just added: Algorithms you can run and practice
Updated Jul 10, 2026 Edit on GitHub

Database Connection Pools

Your app was fine all week. Then traffic doubled, and the database fell over with too many connections while CPU sat at 20% - plenty of headroom, yet everything timed out. The villain is almost never query speed here. It's how many doors you tried to open into the database at once. This guide gives you the mental model for what a connection actually costs, why a pool fixes it, and how to size one without guessing.

How to read this

Read the three phases in order - they build on each other. If you've ever stared at a connection pool timeout log line at 3am, Phase 3 is your destination, but Phase 1 and 2 are what make it make sense.

The phases

  1. What a connection actually costs - the mental model: a connection is memory plus a handshake, not a free function call.
  2. How a pool works and how to size it - reuse a fixed set of connections, and pick the number on purpose.
  3. When pools break: exhaustion, leaks, and serverless storms - the failure modes that page you, and how to survive them.