Operating the Gateway: The New Load-Bearing Tier
What the Gateway Does Per Request
Netflix states the scope plainly in "How Netflix Scales its API with GraphQL Federation (Part 2)" (Dec 2020): the gateway's single purpose is to "parse client queries, then build and execute query plans". Anything else resource-intensive is pushed off-box, except logging and metrics. In practice every request goes through the same pipeline, and each stage has its own way of failing:
What does this cost in latency? Netflix published two numbers that measure different things. At QCon Plus 2020 (Jennifer Shin and Stephen Spalding, "How Netflix Scales Its API with GraphQL Federation"), the first benchmark of their Kotlin gateway, built in July 2019 from Apollo's reference implementation, had "query planning and execution … clocking in at under a millisecond". Part 1 of the blog series (Nov 2020) gives the production-shaped figure: "Query Planning and Execution adds a ~10ms overhead in the worst case", and that includes deserializing the DGS responses and serializing the merged response. The second number is the one to budget with. In a federated gateway most of the CPU goes into JSON in and JSON out. Planning is comparatively cheap, provided the plan is cached.
| Netflix gateway | Kotlin, coroutines for parallel fetches; not open source (as of 2020) |
|---|---|
| Overhead (published) | <1 ms first benchmark; ~10 ms worst case incl. (de)serialization |
| Apollo Router | Rust; defaults: 30 s timeouts, 512-entry plan LRU |
| Consumer scale | >1M GraphQL queries/s across two principal subgraphs (GraphQLConf 2025) |
The Plan Cache Is the Gateway's Hot Path
The query planner part showed what the planner emits. In operations you mostly care whether it has to run at all. Apollo Router keeps an in-memory LRU of plans (supergraph.query_planning.cache.in_memory.limit, default 512), with an optional Redis tier (…cache.redis.urls, entries prefixed plan., default TTL 30 days). The key covers the operation document and the schema, not variable values. So homePage(profileId: $id) is one entry for every member, while a client that inlines the literal homePage(profileId: "42") creates one entry per member and cycles the LRU.
The expensive moment is a schema change. A new supergraph can change the plan for any operation, so the cached plans can't be reused. Before switching traffic, the router precomputes plans for a slice of the hot set (supergraph.query_planning.warmed_up_queries, default 30% of cached entries). Everything outside that slice is planned on first request under the new schema. Cache behaviour shows up in apollo.router.cache.hit.time, apollo.router.cache.miss.time and apollo.router.cache.size, all with kind="query planner". How hard the planner has to work depends on the schema: Apollo's query-planning best-practices page says heavy @shareable use can grow the candidate plans exponentially. experimental_plans_limit (default 10000) silently prunes the search and returns a valid but possibly suboptimal plan. experimental_paths_limit (default unset) aborts the operation instead.
Demand Control: Pricing a Query Before Running It
A REST endpoint has a fixed cost. A GraphQL operation's cost is whatever the client asks for. Netflix's Part 2 post lists "demand controlled" as one of five gateway resilience principles: they rate-limit callers and "run a static query cost calculation on all incoming queries and reject expensive queries to avoid gridlock in gateway and DGS resources." Apollo Router has two layers for this. The first is shape limits under limits.router: max_depth 100, max_height 200, max_aliases 30, max_root_fields 20, parser_max_tokens 15000, parser_max_recursion 500, http_max_request_bytes 2 MB, plus a warn_only switch. The second is cost under demand_control, based on the IBM GraphQL Cost Directive spec: objects, interfaces and unions cost 1, scalars and enums 0, a mutation adds 10, and each list multiplies its subtree by @listSize (a static assumedSize or the value of a slicingArguments such as first). @cost(weight:) overrides the default weight of a field or type.
type Page { rows(first: Int!): [Row!]! @listSize(slicingArguments: ["first"]) }
type Row { titles(first: Int!): [Video!]! @listSize(slicingArguments: ["first"]) }
type Video { title: String! artwork(size: ArtSize!): Artwork bookmark: Bookmark }
# TV home: homePage { rows(first: 40) { titles(first: 75) { title artwork bookmark } } }
# Page 1 + 40 x ( Row 1 + 75 x ( Video 1 + Artwork 1 + Bookmark 1 ) )
# = 1 + 40 x (1 + 225) = 9,041
# Phone home with rows(first: 10) / titles(first: 20): 1 + 10 x (1 + 60) = 611These numbers are the reason the max can't be a single value for every client. A legitimate TV home page scores fifteen times the phone page. Set one global ceiling and either TV fails or the ceiling is too loose to stop abuse. Apollo's docs recommend starting in mode: measure and comparing cost.estimated with cost.actual (the cost.delta instrument) before moving to enforce. Router v2.12+ adds per-subgraph max and list_size. If you want per-client ceilings, which the TV example needs, that isn't one of the documented keys. You would build it from client identity in a coprocessor or plugin, or you'd avoid the problem by safelisting operations (next).
Persisted Operations: Turning an Open API Into a Closed One
Two mechanisms share the name, and they are opposites. APQ (Automatic Persisted Queries) is a bandwidth optimization. The client sends a SHA-256 hash; on a miss the router answers PersistedQueryNotFound and the client retries with the full text, which the router then caches. Any client can register any operation at runtime. A persisted query list (PQL) is a security mechanism. Operations are registered at client build time, and the router can refuse anything else. Apollo's rollout order is three settings under persisted_queries:
enabled: true,log_unknown: true. The router loads the list from GraphOS and serves IDs, and freeform queries still work. Logs show which clients send unregistered operations.safelist.enabled: true. Freeform text is accepted only if it matches a registered operation. APQ must be off (apq.enabled: false), because APQ exists to let clients register arbitrary operations.safelist.require_id: true. Clients may send only an ID. From here the attack surface is the registered set of operations, not the whole schema.
For a first-party TV app this is the natural end state. Every operation the TV sends is known when the app is built, so after this step cost limits and depth limits are mostly checks on your own client team, not defences against strangers. It also changes schema governance (see Schema governance): the registered list is an exact inventory of which fields each client version uses.
HTTP Caching: What Was Lost and What Replaces It
The GraphQL-over-HTTP spec (Stage 2 draft at the GraphQL Foundation) says a server MUST support POST and MAY support GET. GET MUST NOT execute mutations, and 405 is the recommended response when a client tries. A POST body is invisible to every HTTP cache, which is how clients that POST everything lose the CDN layer. GET with a persisted-query ID gets it back: the URL is short, stable and cacheable. Apollo Router's CSRF prevention is on by default, so a GET must carry a non-simple Content-Type, X-Apollo-Operation-Name or Apollo-Require-Preflight, or it is rejected with 400. The spec also defines a custom 294 Partial Success status for responses that carry both data and errors. RFC 9110 requires clients to treat an unknown 2xx as 200, but 294 is not on the heuristically-cacheable list, so a CDN may treat it differently from 200.
For the TV home page the CDN question is mostly a distraction. The payload is member 42's rows, bookmarks and entitlements, and no shared cache should hold it. What is shareable are the parts inside it: Video metadata and Artwork URLs are the same for millions of members. Apollo's answer is caching per entity inside the router. It was first shipped as preview_entity_cache. In January 2026 Apollo announced response caching (response_cache, Router v2.10+) as its "complete re-write and replacement". It caches root-field results and each subgraph's contribution to each entity separately in Redis. TTL comes from the subgraph's Cache-Control (derived from @cacheControl), taking the minimum across parts. scope: PRIVATE data is cached per user through private_id, and entries can be invalidated through @cacheTag(format: "video-{$key.id}") and a POST /invalidation endpoint. Responses that contain errors are not cached.
| Home-page entity | Cache at gateway? | Why |
|---|---|---|
Video title, synopsis | Yes: public, minutes to hours | Identical for every member in a locale; the catalog subgraph sets maxAge. |
Artwork(size:) | Yes: public, keyed by args | Device-dependent, but a small set of sizes; very high reuse. |
Row / Page for member 42 | Private, short, or not at all | Personalization is recomputed often; a stale row list is a product bug, not a latency win. |
Bookmark | No | Changes on every play; a stale value brings back the "resume from the wrong place" bug. |
Entitlement / plan | No (or seconds, private) | A decision about what the member may play; a stale grant is a security issue. |
Netflix took the opposite default in 2020. Asked about caching at QCon, Spalding said "we are letting the Federated services themselves make the decisions on caching", because caching opens "a Pandora's Box of questions about how you manage and expire those caches", and Shin added that they want the gateway "as dumb as possible". That fits the EVCache world of the Netflix Architecture guide's EVCache part: each subgraph already sits on its own in-AZ cache, so a gateway cache would be a second cache with a second TTL owned by nobody. Whether Netflix's consumer gateway caches today is not published.
Timeouts, Retries and Partial Responses
The Hystrix world gave every dependency its own timeout, thread pool and fallback. The router's equivalents are coarser. Under traffic_shaping both the router timeout and subgraph timeouts default to 30 s. A router timeout returns HTTP 504. A subgraph timeout applies per fetch (one operation can make several fetches to the same subgraph) and produces a normal 200 with that branch null and an entry in errors, so the rest of the plan still returns data. Apollo's guidance is to keep the router timeout above every subgraph timeout. Router-level global_rate_limit (503 when hit) and concurrency_limit exist as well. Retries are not a router feature. experimental_retry was deleted; the router's config migration says it was "unused and badly implemented". deduplicate_query collapses identical in-flight subgraph requests across client requests, but it is off by default and requires identical path, headers and body. Requests carrying member 42's auth headers will never match another member's, so it doesn't help personalized traffic.
The plan's shape determines the latency budget, because timeouts along a Sequence add up:
Sequence
L1 Fetch(personalization) page + rows + video ids budget 80 ms
L2 Parallel
Fetch(catalog) _entities(Video x ~3000) budget 120 ms
Fetch(member) _entities(Member 42) budget 40 ms
L3 Fetch(images) _entities(Video) artwork(size) budget 80 ms
---------------
worst case with 30 s defaults: 30 s + 30 s + 30 s = client gave up long ago
worst case with budgets: 80 + max(120, 40) + 80 = 280 ms(Budgets are illustrative, not Netflix figures. The plan shape follows see The query planner.)
Observability: When Every Response Is a 200
Netflix names the core difficulty in the Part 2 post: "In GraphQL, almost every response is a 200 with custom errors in the error block." Dashboards built on HTTP status codes show a healthy system while the continueWatching row is null for everyone. Netflix's fix was to extract the custom error codes from each response and emit them to Atlas as metrics. They wired the gateway and every DGS into Zipkin-based tracing (Edgar) with distributed log correlation, and deep-linked every type and field in a trace to the owning team's support channel, with the goal of reducing "the number of times the gateway team needs to get involved." That last point is the organizational one. At 200+ subgraphs, a gateway team that triages every error becomes the old API team again.
Apollo's version of this has three layers. OpenTelemetry spans for the router, supergraph and subgraph services, with graphql.operation.name and the subgraph name. Field-level traces (FTV1): the router asks subgraphs for per-resolver timing with the header apollo-federation-include-trace: ftv1, sampled by field_level_instrumentation_sampler (1% by default), and this is what feeds field-usage statistics for safe deprecation (see Schema governance). The plan itself: with plugins.experimental.expose_query_plan: true, sending Apollo-Expose-Query-Plan: true returns the plan in extensions, and dry-run plans without executing. Don't enable plan exposure in production without restricting it, because it describes your backend topology to anyone who asks. The same trade-off applies to errors. By default the router redacts subgraph error messages to "Subgraph errors redacted" (include_subgraph_errors, overridable per subgraph), so the client learns that a branch failed but not why. Leave redaction on at the edge, and make sure the trace carries the original error; otherwise nobody gets the reason.
Blast Radius: The Schema Publish Is the Riskiest Deploy
When composition fails, nothing happens, which is the safe outcome. GraphOS keeps serving the last successful supergraph, and a router whose poll fails keeps the last one it fetched. The dangerous change is the one that composes successfully and is still wrong, because the router applies it to every instance at the next poll:
| Change that composes fine | What breaks |
|---|---|
| Schema published before the subgraph code that serves it is deployed | The planner routes the new field to a subgraph that returns a validation error → every operation selecting it gets a null branch + error. |
@override(from: "legacy") on Video.title | 100% of title traffic moves to the new subgraph at once. That's why progressive @override(label: "percent(5)") exists (see The migration playbook). |
A @key or @requires change | Plans get an extra sequential hop (see The query planner); latency rises with no error. |
| Composition run with a newer federation version than the router supports | Apollo: a supergraph that "causes the router to fail on startup", so new instances can't boot during a scale-up. |
Netflix's registry (in-house, Kotlin, event-sourced on Cassandra, integrated with Spinnaker) accepted a pushed schema only if it was valid, composed with every other DGS schema, and was backwards compatible (Part 1). All three checks are static, and every row in the table above passes them. In 2020 the gateway "dynamically updates its schema by polling the schema registry". Netflix was moving the federation config to a versioned S3 bucket, "making the gateway resilient to schema registry failures", and planned canary analysis "for gateway deployments and, eventually, schema changes." Read that last clause carefully: at that point a schema change reached the whole fleet without a canary, even though the schema is the gateway's routing table. Versioning is also what makes rollback possible. If the last N composed configs are kept as immutable objects, rolling back means pointing the gateway at config N−1, not reverting code in five repositories and recomposing. (Reasoning; the post gives the motivation as registry resilience.) By the 2023 consumer migration ("Migrating Netflix to GraphQL Safely") the gap was closed for the risky schema changes. A Sticky Canary ran two instances of the GraphQL gateway: a baseline on the existing schema, routing to the GraphQL Shim, and an experiment on the proposed schema with @override routing to the new Video service. Zuul assigned each customer to one of the two clusters by device and profile, "similar to a bucket hash". Experiments grew from hour-long runs on tiny allocations to multi-region runs of 12 hours to a day. So the unit of canary is a (gateway fleet, supergraph) pair, which only works if the gateway can be pinned to a specific schema version.
Scaling the Tier
The five principles from Netflix's Part 2 post are still a good checklist. Single purpose: no business logic in the gateway. Stateless: any instance can plan and execute any request. Demand controlled: see above. Multi-region, with regional failover to limit blast radius. Sharded by functionality: the code is the same everywhere, but subscriptions run on a separate fleet so long-lived connections can't use up the connection budget of short queries. The same logic applies to a TV home page, which is expensive and heavily personalized, next to a cheap profile-switcher query. The Sticky Canary above adds another use for the same capability: two gateway clusters that differ only in the supergraph they load, and an edge router (Zuul) that decides which cluster a customer uses. At consumer scale the gateway is also a cost line. Tejas Shikhare's QCon SF 2022 talk (InfoQ write-up) reported the federated platform serving "more than 1 billion daily requests". The 2025 consumer figure below is almost two orders of magnitude larger (1M/s ≈ 86B/day). That isn't a contradiction: the two numbers describe different graphs in different years, and neither should be quoted as "Netflix's GraphQL traffic". Stephen Chambers' GraphQLConf 2025 abstract reports a fix "at the query planning layer" that cut requests per second by 20% and saved "hundreds of thousands of dollars", against two principal subgraphs serving over a million queries per second. The abstract doesn't describe the mechanism, so don't assume one.
The Invariants
- Guarantees: A failed composition never reaches the router; a cached plan is reused for every set of variable values; a subgraph timeout returns partial data with an error instead of failing the whole response; within one fetch, duplicate entity representations are sent once; a
require_idsafelist limits the reachable surface to registered operations. - Does not guarantee: That a successful composition is safe to route; that plans survive a schema publish; that an HTTP 200 means the page rendered; that identical data for different members is fetched once (cross-request dedupe needs identical headers); retries or per-dependency isolation (neither is a router feature by default); or that CDN caching still works for anything that isn't a GET with a persisted ID.