GraphQL DataLoader Pattern
ELI5 — The Vibe Check
The DataLoader pattern collects all the data requests that happen in a single tick of the event loop and batches them into one query. It's the standard solution for N+1 problems in GraphQL. Without it, every nested field makes its own database query and your server melts.
Real Talk
The DataLoader pattern is a batching and caching utility specific to GraphQL resolver execution. It defers individual load calls within a single execution frame, collects all requested keys, and executes a single batch function to fetch all data at once. The pattern provides per-request caching to avoid duplicate loads. Created by Facebook and available as the 'dataloader' npm package.
When You'll Hear This
"Create a new DataLoader instance per request to avoid cache leaks between users." / "The DataLoader pattern turned our 200-query GraphQL response into 5 batched queries."
Related Terms
Batch Loading
Batch loading is fetching many things in one call instead of one at a time. Instead of asking 'give me user 1... give me user 2... give me user 3...
Data Loader
DataLoader batches and caches database calls in GraphQL. Without it, fetching 100 users with their posts makes 101 database queries (the N+1 problem).
GraphQL
GraphQL is like ordering food where YOU specify exactly what you want on your plate.
N+1 Problem
The N+1 problem is when your code makes 1 query to get a list of things, then N more queries to get related data for each thing.