Solving the Graphql N+1 problem - jaredgorski.org

Back to notes

Solving the Graphql N+1 problem

Keywords: graphql, data, server, api, problems, n+1, performance bottleneck
Date:
  • The N+1 problem is one of the common conceptual problems with Graphql
  • Solutions:
    • batching
      • rather than resolve each resolver function individually and immediately, defer resolution, collect all unique fields needed to complete the request, and then invoke "batch resolvers" that return data for all necessary fields in one request
    • caching/memoization
      • as resolvers execute, cache unique data from requests and attempt to resolve consecutive fields with the cached data before executing the normal server request
  • Utilities:
    • Dataloader (JS), a Facebook-made utility that provides batching and caching methods
    • Graphql Batch (Ruby), like Dataloader but made by Shopify for Ruby

Backlinks: