A story about a 0.143ms query that somehow pinned our Postgres CPU at 98%, and the one formula from queueing theory that finally explained why.
The Symptom
We run a small, boring-sounding microservice: it hands out unique IDs to callers. One endpoint, one job. GET /id?uniqueKey=... → here's your ID, go away.
It should be one of the fastest endpoints in our stack. Grab an available ID from a pool, mark it as taken, return it. Milliseconds, easily.
Except in production, at a perfectly reasonable ~50 requests per second, this is what we were actually seeing:
Average response time: 8–12 seconds.
Worst case: 67 seconds.
Postgres CPU: pinned at ~98%.
For an endpoint that does one SELECT , a tiny bit of logic, and one UPDATE .…