An endpoint gets slower as results grow
“The endpoint performs acceptably for ten records but collapses for hundreds, while database query count rises with result count.”
ERROR CODES YOU MAY SEE
A code is a clue. Use its meaning and surrounding evidence to narrow the cause.
57014PostgreSQL SQLSTATE · platformThe query was canceled (query_canceled).
Read the accompanying message to identify the cancellation cause. Check timeouts and query traces; cancellation alone does not establish N+1 access.
Official reference for 57014 (opens in new tab)Code definition reviewed
THE PRINCIPLE
Observe query count and shape—not only endpoint duration.
FIRST MOVES
- Trace database calls and confirm whether query count grows linearly with rows.
- Fetch related data in a join, batch query, or dataloader based on access shape.
- Select only required fields and confirm supporting indexes with EXPLAIN ANALYZE.
- Add a query-count or production-shaped performance regression test.
TOOLS: THEN → NOW
Manual SQL logsOpenTelemetry traces and ORM query instrumentation
Eager-load everythingPurposeful joins, batching, and projections
PATTERN SNAPSHOT
const orders = await db.order.findMany({
where: { userId },
include: { merchant: true },
take: 50,
});CLOSE THE AI. EXPLAIN THIS.
Why can eager loading every relation be as harmful as N+1 querying?Guide reviewed