polycratia

The endpoint was fast when I ran it. Fast in staging too. In production it took three seconds, but only during the hours the ops team was working in the admin panel.

I started where you start: the queries. They were fine. The handler's own work was a small slice of those three seconds. The rest of the time the request was doing nothing at all. It sat there waiting to get a database connection out of the pool.

The pool was being drained by an export in the admin panel. Long transaction, opened a connection, then called an external carrier API from inside that transaction and held the connection for the whole round trip. A few of those running at once and ordinary catalog traffic simply queued behind them.

Two changes. The external call moved outside the transaction boundary, so no connection is held while you wait on someone else's network. And the reporting path got its own pool, so an operator's export can't starve customer requests.

What I do differently now: I instrument connection acquisition as its own span, separate from query time. Without that split, waiting in line looks exactly like slow code, and you lose a week optimizing the wrong thing.

So when your endpoint is slow, I'd measure the time it spends waiting for a resource someone else is holding...

react

$ new-project --brief

or email hey@polycratia.com