BlogsShopifyGraphQL Batching for N+1 Problem

GraphQL Batching for N+1 Problem

GraphQL Batching for N+1 Problem

2
posts
2018–2026

Shopify has developed and enhanced its GraphQL execution engine by introducing GraphQL Cardinal, a breadth-first execution engine. This new engine resolves each field once across all objects, rather than once per object, significantly improving performance for high-cardinality list queries. This addresses the hidden costs of depth-first traversal, such as linear scale amplification and field-level overhead, leading to substantial reductions in execution time and memory usage. The migration of a massive production stack to this new model has been a key focus.

2026

Shopify’s journey to faster breadth-first GraphQL execution (2026) - Shopify

3/12/2026

Introduced GraphQL Cardinal, a new breadth-first execution engine for GraphQL. This engine resolves fields once per field across all objects, contrasting with the traditional depth-first execution model. The post details the hidden costs of depth-first traversal, including linear scale and field-level overhead, and presents the breadth-first hypothesis and its implementation in Cardinal. Benchmarks show up to 15x faster CPU-bound execution and 90% less memory usage for large list queries. The post also discusses the migration of a large production stack to this new execution model.

2018

Solving the N+1 Problem for GraphQL through Batching - Shopify

4/24/2018

Introduced the GraphQL Batch Ruby library, inspired by DataLoader, to solve the N+1 problem in GraphQL by batching data requests. This library allows resolvers to return promises for data, which are then grouped and loaded efficiently, reducing datastore round trips. The library has been open-sourced.