Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 8 min read How-to mediumAdept

Querying Strategies for GraphQL Clients

GraphQL client queries tend to grow slower and harder to roll out as features accumulate, and Shopify's Orders & Fulfillments web and mobile teams work through a progression of strategies against a sub-one-second mobile page load goal. Starting from a single products query, they add cursor-style pagination with page-size parameters and hasNextPage, and gate new fields behind feature flags using @include/@skip directives. Chaining queries on remote flags is costly because it serializes round-trips, so it should be avoided or moved app-wide. Splitting non-paginated parts such as filters, permissions and banners into parallel queries enables faster loads, partial rendering and fewer merge conflicts, provided performance tripwires and server-side monitoring are in place.

Assumes: GraphQL queries and directivesPagination concepts

Related posts

  • Shopify’s journey to faster breadth-first GraphQL execution

    Shopify Engineering hardMaster

    Shopify built GraphQL Cardinal, a breadth-first GraphQL execution engine that calls each field resolver once with the full set of objects at that level instead of once per object. Depth-first execution, used by graphql-ruby and graphql-js, multiplies per-field overhead from tracing hooks, authorization and dataloader promises by response breadth. Cardinal builds a typed execution tree, runs a bottom-up lookbehind planning pass inspired by Grafast, and executes generation by generation with flat object/result sets in a queue-driven loop rather than recursion. Large list queries ran up to 15x faster with 90% less memory and saved over 4s at P50. The tradeoffs are that errors are inlined and located by a final depth traversal, and that migrating a monolith from one-in/one-out resolvers requires an incremental bridge.

  • How we use GraphQL at Europe's largest fashion e-commerce company

    Zalando Engineering easyNovice

    Zalando replaced a sprawl of per-page and per-platform Backend-for-Frontend services with a single unified GraphQL API owned via a shared monorepo across 12+ domain teams. The BFFs had duplicated effort, fragmented security and observability, and produced inconsistent data across web and app. The graph is built on Entities such as Product and Campaign and runs on their own GraphQL engine, graphql-jit, under a strict no-business-logic rule. Since 2018 it has grown to serve over 80% of web and 50% of app use cases, with adoption driven by documentation, training and schema consultation, and god-component risk handled through contribution principles, circuit breakers, timeouts, retries and per-platform bulkhead deployments.

  • Rate Limiting GraphQL APIs by Calculating Query Complexity

    Shopify Engineering mediumAdept

    Shopify's GraphQL Admin API rate-limits by calculated query cost instead of request count: clients get 50 points per second up to a 1,000-point bucket, and each query is priced by static analysis before execution. Objects, interfaces and unions cost 1 point, and scalars and enums are free. Connections cost 2 plus the number of requested objects, and mutations cost 10 to reflect side effects. Responses report requested and actual cost in an extensions object, and any unused requested cost is refunded. Shopify found calculated cost correlates linearly with execution time, which makes server load predictable and rewards clients for requesting only the data they need.

  • Optimize GraphQL Server with Lookaheads

    Zalando Engineering mediumAdept

    Zalando's GraphQL server uses lookaheads on the resolver's info AST (fieldNodes and selection sets) to work out which sub-fields a query requests, then forwards them to backends that support partial responses via a fields parameter. Dependency maps translate schema fields to backend object paths for the request, and per-field transformer maps build the schema response from partial backend data without null-check sprawl. DataLoader batches product lookups across a query by merging ids and taking the union of requested backend fields, since most backends can't select different fields per id.

  • Building single page applications with ClickHouse

    ClickHouse mediumAdept

    ClickHouse can serve as a direct browser-queried backend for single page applications, removing the API server layer for demos, prototypes and analytics UIs. Doing this safely depends on HTTPS-only access, CORS configuration, parameterized queries to prevent SQL injection, read-only users with role-based access control, query complexity limits and quotas to stop rogue clients from overwhelming the database. Practical guidance covers choosing JSON output formats (streamable EachRow variants for large results, Arrow for high-volume rendering), reading progress and summary headers, the `wait_end_of_query` tradeoff, handling mid-stream errors returned with HTTP 200, and preferring the official @clickhouse/client-web library. ClickHouse Cloud Query Endpoints are suggested for teams wanting an API layer instead.

The quest for software engineering knowledge.

Look:
Layout: