Free Tool

What Is Your N+1 Query Costing Your Database?

N+1 is the most common ORM performance mistake. Most teams know it exists but don't know how bad it is. Enter your traffic numbers and see the real database load.

92%

avg query reduction

1 day

same-day diagnosis

1 line

typical ORM fix

Your API & Database Setup

Fix with: select_related() / prefetch_related()

Requests hitting your N+1-affected endpoint under normal traffic

50 req/s
1 req/s500 req/s

How many items does your ORM loop over per request?

20
2500

How long does each individual ORM query take? (check slow query log)

25ms
1ms1,000ms

RDS, Aurora, Cloud SQL, or self-hosted monthly cost

$2K
$50$20K

Queries fired per request

21

1 list query + 20 item queries — should be 2

Critical — 20× query overhead

Database load: now vs fixed

Current queries/sec1K q/s
After eager loading100 q/s
Query reduction90% fewer queries

Latency overhead now

500ms

N × query time added to every response

After fix

25ms

One batch query instead of N sequential

Queries eliminated/day

82.1M

DB work removed from your server

Est. monthly savings

$540

Via DB right-sizing after load drops

Before vs After: What Changes

One code change. No schema migration. No infrastructure work.

Current (N+1)
Queries per request21
DB queries/second1K q/s
Added latency per req500ms
Monthly DB cost$1,500
After (select_related() / prefetch_related())
Queries per request2
DB queries/second100 q/s
Added latency per req~25ms
Est. monthly DB cost$960

Query reduction

90%

Latency saved/req

475ms

Annual savings

$6K

We find every N+1 in your codebase in one business day.

We instrument your endpoints, correlate slow query logs to application code, and deliver a prioritised fix list — typically a handful of ORM changes, not a schema redesign.

Why N+1 is silent but expensive

It doesn't look broken

APIs with N+1 patterns respond correctly — they're just slow. No errors, no timeouts. It takes query-level monitoring to even know it's happening, which is why most teams discover it months or years in.

It scales with your users

At 10 req/sec it's annoying. At 100 req/sec it saturates your database. The pattern compounds: more traffic → more queries → slower responses → more retries → even more queries.

The fix is one line of code

In Django: select_related(). In Rails: includes(). In Prisma: include: {}. The fix rarely touches your schema or requires downtime. It's almost always an ORM configuration issue, not an architecture problem.

How to confirm you have N+1: Enable query logging in your ORM, make one API call, and count the database queries. If the count is proportional to the number of items returned (not constant), you have N+1.

Frequently Asked Questions

What is the N+1 query problem?

It happens when your ORM fetches a list of records with one query, then fires a separate query for each record's related data — N additional queries for N items, instead of one batch query. Most ORMs lazy-load relationships by default, so this happens silently whenever code iterates over a collection and accesses a related field.

How much latency does N+1 actually add?

Each additional query carries its own network round-trip, connection overhead, and execution time — so an endpoint doing 1 query becomes one doing N+1, with total added latency roughly equal to N times the per-query time. A common symptom: if doubling your data size roughly doubles your response time instead of adding a small, constant amount, N+1 is usually the cause.

Why does N+1 get worse as traffic grows?

The pattern compounds with concurrency. At low request rates, the extra queries are wasteful but tolerable; as request volume rises, the same N-times query multiplication saturates database connections and CPU faster than a properly batched query would — which is why N+1 issues often only become visible once traffic scales past what testing ever covered.

How do I confirm I actually have N+1 queries?

Enable query logging in your ORM (or use an APM tool), make one API call to the affected endpoint, and count the queries fired. If the count scales with the number of items returned rather than staying constant, that's N+1. Most ORMs log this directly — Django's debug toolbar, Rails' query log, or Prisma's query event logging all show it clearly.

Does fixing N+1 require a schema change or downtime?

Almost never. The fix is typically a single eager-loading call in the ORM — select_related()/prefetch_related() in Django, includes() in Rails, include: {} in Prisma — that tells the ORM to batch the related-record fetch into one or two queries instead of N. No schema migration or infrastructure change is required.

Know you have N+1. Don't know which endpoints?

We instrument your application, identify every N+1 pattern across all endpoints, and deliver a fix plan — usually within one business day of connecting to your environment.