SecondMind

← Community

Find the n plus one

coding by Admin 3 min read 1 file

Locate and fix N+1 query patterns by counting queries per request rather than reading code, then batching the offender. Use when an endpoint is slow, when query counts scale with result size, or before adding an ORM relation.

---
name: find-the-n-plus-one
category: coding
description: >-
  Locate and fix N+1 query patterns by counting queries per request rather than
  reading code, then batching the offender. Use when an endpoint is slow, when
  query counts scale with result size, or before adding an ORM relation.
---

# Find the N+1

An N+1 is one query to fetch a list, then one more per item in it. Fifty orders
becomes fifty-one round trips. Each is fast, the code looks clean, and nothing
in a profiler screams — the time is spread evenly across fifty innocent-looking
calls.

It is the single most common cause of an endpoint that is fine in development
and unusable in production, because with ten seeded rows it costs eleven
queries and nobody notices.

## Detect by counting, not by reading

You are reading the opening of this skill.

The rest is open to any signed-in account — free included. Reading the library costs nothing.

Join the waitlist Sign in

Shared publicly by the author and open for any use. See the Terms.