Solving the Graphql N+1 problem -

Solving the Graphql N+1 problem

graphql, data, server, api, problems, n+1, performance bottleneck
  • The N+1 problem
  • 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