NODEJS Contents

N+1 Query Problem

The N+1 query problem silently destroys performance; batch and join intelligently to reduce database round trips.

On this page

What Is N+1

N+1 occurs when fetching a list and then querying related data individually for each item.

Example Problem

SELECT * FROM users;
-- then for each user:
SELECT * FROM orders WHERE user_id = ?

Solution

Use JOINs or batch queries to reduce round trips.

Production Insight

N+1 often appears after refactoring into repository layers. Monitor query counts per request.