Q20: How does DataLoader solve the N+1 problem?

Difficulty:IntermediateTopic:Performance

DataLoader (created by Facebook) solves N+1 through batching and caching during execution.

It defers individual load requests occurring within a single event loop tick, combines those IDs into a single batch array, and executes one consolidated batch query (e.g., WHERE id IN (...)).

Key Takeaways
  • DataLoader batches concurrent resolver requests in the same event loop frame.
  • It replaces $N$ individual queries with a single batch IN query.
Knowledge Check

DataLoader aggregates individual resource keys across which processing window?