When an endpoint takes 3 seconds, the database is usually not the problem. The time goes somewhere after the data has already arrived.
The mechanics are boring, and they repeat.
A list endpoint runs one fast query, then hydrates each row's relations one at a time. Thirty rows, four relations each, and the endpoint has issued a hundred and twenty queries that are individually fast and collectively fatal. Nothing in the slow-query log looks wrong, because nothing was slow. The log shows a hundred and twenty healthy statements and zero offenders.
Then serialization adds a layer of its own. A nested serializer that resolves a computed field per object will re-enter the ORM per object. A field that formats money or dates through a heavier code path does it per row. None of that shows up in database metrics, because it happens entirely inside the application process after the connection is released.
So the honest diagnostic order is this: count the queries per request before you optimize any single one of them. Then look at how much of the wall clock sits between the last query returning and the response being written. If that gap is large, no index will help you.
What I design for now is bounded work per request. A list endpoint should issue a number of queries that does not grow with the number of rows returned, and the response shape should be decided by what the caller needs, not by what the model happens to expose. Pagination is a correctness property rather than a UI nicety: an endpoint with no upper bound on rows has no upper bound on latency.
The second-order effect matters more in payment and marketplace backends. A 3-second endpoint under a 2-second client timeout stops being a performance issue and becomes a retry generator, and retries against a non-idempotent write turn slowness into duplicates. I have seen latency reclassified from a performance ticket to a data-integrity ticket exactly that way.
Caching the response is the common reaction and usually the wrong first move. It hides the per-row work instead of removing it, and the first cache miss under load reproduces the original failure with a thundering herd attached.
For anyone chasing a slow endpoint right now: check whether your instrumentation measures query time, or request time minus query time. Those two numbers point at completely different fixes.