Connection pooling in five minutes
What pgbouncer actually pools, and the two settings that matter most.
There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let's start with the thing that actually broke.
Setting the scene
The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I'd never seen before.
Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I've kept it ever since, even as the rest of the stack changed twice over.
- Latency at p50, because most users live there
- A second point, kept short on purpose
The naive approach
I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.
The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I'd never seen before.
Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: what pgbouncer actually pools, and the two settings that matter most is a decision you make once and revisit deliberately.