Eliminate the N+1 query problem in a GraphQL server by batching all ID-based data fetches into one database call
Reduce database round trips in a Node.js API by collecting many individual record lookups into a single query
Cache records within a single request so the same user or item is only fetched from the database once
Speed up parallel GraphQL resolver execution without changing how individual resolvers are written
| graphql/dataloader | mishoo/uglifyjs | drksephy/es6-cheatsheet | |
|---|---|---|---|
| Stars | 13,366 | 13,393 | 13,336 |
| Language | JavaScript | JavaScript | JavaScript |
| Setup difficulty | easy | easy | easy |
| Complexity | 2/5 | 2/5 | 1/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
DataLoader is a small JavaScript utility that solves a specific performance problem in web servers: when your application needs to fetch many individual records from a database or API, it tends to make one separate request per record, which is slow. DataLoader collects all those individual requests that happen at nearly the same time and sends them together as a single grouped request, then hands each caller back their specific result. This technique is called batching. The library originated at Facebook in 2010, where engineers faced the same problem at massive scale. The original internal version was called "Loader" and became part of Facebook's data infrastructure, eventually forming part of the foundation for GraphQL. The JavaScript version in this repository is a simplified, publicly available implementation designed for Node.js services. Using DataLoader involves writing a batch function: you tell the library how to fetch a list of records given a list of IDs, and DataLoader handles everything else. When different parts of your application each ask for a user record by ID within the same request, DataLoader waits until the current tick of execution finishes, collects all the IDs, calls your batch function once, and distributes results back to each caller. A naive approach might make four database round trips, with DataLoader it becomes one or two. Beyond batching, DataLoader also caches results within the scope of a single request. If two parts of the code ask for the same user record, the second request is served from memory without hitting the database again. This cache is per-request, not shared across users, so it does not replace a system-level cache like Redis. The library is commonly used with GraphQL servers because GraphQL resolvers naturally produce many small, independent data fetches that would otherwise create a well-known performance problem called the N+1 query problem. DataLoader is the standard solution to that problem in the Node.js GraphQL ecosystem, and the repository documents its API, batching behavior, caching rules, and several advanced options like custom batch scheduling and cache key customization.
DataLoader is a small Node.js utility that batches and caches database or API requests, turning many individual round trips into a single grouped call to eliminate the N+1 performance problem.
Mainly JavaScript. The stack also includes JavaScript, Node.js.
Setup difficulty is rated easy, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.