polycratia

A 3-second API response is rarely 3 seconds of work. Usually it is a few milliseconds of work, and the rest is time spent waiting in line.

The mechanics are boring and consistent. Your web process has a bounded pool of database connections. Something else in the same system borrows them and holds on: a reconciliation job, a report export, a batch writer keeping a transaction open while it waits on a third-party HTTP call. The request handler never got slower. It just could not start.

That is why profiling the endpoint finds nothing. The span you measure begins when the query runs, and the lost time happened before that. Timing inside the handler is blind to the queue sitting in front of it.

So I measure connection checkout wait separately from query execution, and pool saturation over time instead of averages. Once those are two different numbers, the shape gives itself away: p50 flat, p99 cliff-shaped, lining up with a background schedule rather than with traffic.

What fixes this is isolation rather than optimization. Separate pools for the request path and the worker path. A hard ceiling on how long any transaction may hold a connection. No external calls inside an open transaction, ever. That is where a slow partner becomes your outage.

Latency work goes wrong when you treat it as a code problem. Most of it, I think, is a capacity-sharing problem between the things that serve users and the things that run behind them.

So when your p99 spikes, the number worth having is whether that time went to executing or to waiting...

react

$ new-project --brief

or email hey@polycratia.com