polycratia

Three seconds on an API response is rarely slow code. It's a chain of network calls that someone decided the request had to block on.

When I profile an endpoint like that, the handler itself is usually trivial. The time sits in two places.

First, serialization. The query looks fine on its own, then the serializer walks relations and fires one more query per row. That loop never shows up in a diff, so review tends to slide past it. It exists only at runtime, and it scales with the data a real account carries, not the data the fixtures had.

Second, outbound calls that ended up inline because at the time that was the simplest thing: a verification provider, a carrier rate quote, a price lookup. Each one is acceptable by itself. Stacked in sequence inside one request, they define the response time, and your service inherits the worst latency among the dependencies it touches.

So the fix is not usually an optimization pass. It's a modeling decision: what does the caller actually need to know right now, and what does the system merely need to know eventually.

In payment and compliance flows I treat that split as part of the design. Persist the intent, return an explicit state, and hand the slow dependency to a worker that drives that state forward. The endpoint gets fast because it stopped pretending to be synchronous, not because the code got cleverer. Each outbound call gets a timeout and a state of its own, so a degraded provider shows up as a pending record instead of a hanging request.

The measurement habit that makes this visible: stop tracking endpoint total latency as one number. Track time per dependency inside the request. Total latency tells you that something is slow. Per-dependency timing tells you which decision to reverse.

Most of the multi-second endpoints I've inherited were not performance problems. They were boundary problems wearing a performance costume.

There is probably a dependency sitting in your request path right now that doesn't need to be there before you respond...

react

$ new-project --brief

or email hey@polycratia.com