Shopify2023-10-18Explainer
Shopify’s journey to faster breadth-first GraphQL execution
Summary
Shopify describes how high-cardinality, deeply nested GraphQL queries exposed execution overhead beyond data loading, with field resolvers assembling responses consuming much of request time. Its GraphQL Cardinal engine replaces conventional depth-first traversal with breadth-first execution, resolving each selected field once across an aggregated set of objects and reducing repeated field-level work. For large list queries, Shopify reports up to 15x faster execution, 90% less memory use, and reductions of many seconds in P50 latency. The migration included a tuned interpreter, cheaper tracer behavior, shadow verification, benchmarks, and ongoing conversion of tens of thousands of legacy resolvers, while future work includes asynchronous patterns and lower-level C bindings.
Context
Shopify supports deeply nested GraphQL queries with dynamic breadth reaching tens or hundreds of thousands of objects. Trace analysis showed that field resolvers assembling responses often consumed more request time than I/O, while conventional depth-first execution repeated field overhead, authorization, instrumentation, and lazy promise work for every object.
Approach / What changed
Shopify built GraphQL Cardinal, a breadth-first execution engine that resolves each field once across a set of objects. The migration also introduced a tuned interpreter, breadth-compatible tracers, resolver translation tools, a shadow verifier, benchmarks, and migration tracking for tens of thousands of legacy field implementations.
Takeaways
Conventional depth-first GraphQL traversal processes each object's subtree independently, so field execution and its associated overhead scale linearly with the response breadth.
Cardinal gives field resolvers sets of objects and mapped results, making breadth batching native to the execution engine instead of layering it on depth traversal with dataloaders.
Shopify reports up to 15x faster execution and 90% less memory for large list queries; regressions found during resolver migration have so far been attributed to translation errors.
Source and freshness
- Source
- shopify.engineering
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.