polycratia

Three seconds of API latency is usually not time spent doing work. It's time spent waiting for a turn.

You see it when the handler's own instrumentation and the client disagree. Inside the handler everything sums to a couple hundred milliseconds, and the caller measures three seconds. Nothing is lying. The missing time happened before the handler ran: the request sat in an accept queue, waited for a worker, or blocked checking out a database connection.

And that wait is rarely manufactured by the endpoint that looks slow. A shape you see often in payment systems: a handler opens a transaction, then calls a provider over HTTP while it is still holding the connection. Every such request parks a pooled connection for the duration of someone else's network. Under normal traffic nobody notices. Once concurrent in-flight calls exceed the pool, every endpoint in the service degrades at the same moment, including the ones that only read a row.

So the first question I ask is not which query is slow. It is what is holding a scarce resource while waiting on something it doesn't control. Pools, workers and threads are finite and shared, and per-handler timing doesn't show them.

The fix is boring. Don't hold a database connection across a network call. Keep pool size and worker count in a deliberate ratio instead of at defaults. Measure queue wait as its own number instead of inferring it from totals.

A profiler shows you where time is spent. It will not show you time spent waiting to start.

I'd like to know whether, when you have chased one of these, it presented as a single slow endpoint or as the whole service going soft at once...

react

$ new-project --brief

or email hey@polycratia.com