intermediatetermWeb foundationsWeb foundations / Backend and APIs / N+1 Queries
IntermediateNot yet reviewed

N+1 Queries

A common ORM performance problem where an application executes 1 initial query followed by N additional queries to fetch related data.

Definition

A common ORM performance problem where an application executes 1 initial query followed by N additional queries to fetch related data.

Use case

Fetching 50 user posts and triggering 50 separate SQL calls for author info instead of using a single JOIN or IN batch query.

Related terms

Documentation

Eager loading associations

Ruby on Rails Guides · Docs · link checked 2026-10-16

The classic ORM trap and the one-query fix, shown in Rails.

Suggest a change