What GraphQL Actually Changes
The Schema Is the Contract
In both the Groovy and the Falcor eras, the contract between a device and the server was code: an adapter endpoint, or a set of route patterns the Falcor router matched at runtime. In GraphQL the contract is a schema. Every field has a type and a nullability, and every request is validated against the schema before execution. The spec is explicit that a request error means "execution does not begin and no data is returned." Here is the TV home page as a schema. The same entity names are used through the whole guide:
Running example — the home-page schema as one (not yet federated) graph
type Query {
me: Member! # the signed-in profile, member 42
homePage: Page!
}
type Page { id: ID! rows(first: Int!): [Row!]! }
type Row { id: ID! title: String! videos(first: Int!): [Video!]! }
type Video {
id: ID!
title: String! # localized: needs Member.language
isPlayable: Boolean! # needs Member entitlements + plan
artwork(width: Int!, height: Int!): Artwork
bookmark: Bookmark # continue-watching position, may be absent
}
type Member {
id: ID!
maturityLevel: Int!
language: String!
avatar: Artwork
plan: Plan!
entitlements: [Entitlement!]!
}
type Artwork { url: String! width: Int! height: Int! }
type Bookmark { positionSeconds: Int! updatedAt: String! }
type Plan { tier: String! maxStreams: Int! }
type Entitlement { region: String! videoIds: [ID!]! }Three things the schema gives you that Falcor paths never did:
| Build-time checks | A client query can be validated in CI against the schema. A misspelled field fails the build, not a 2 a.m. page. |
|---|---|
| Introspection | The schema describes itself. Docs, IDE autocomplete and generated client types come free. This is the "self documentation" and "much better tooling" Netflix cited (see The BFF era). |
| One resolver per field | Netflix's Studio team gave this as the reason they saw fewer data inconsistencies: "every field in GraphQL resolves to a single piece of data-fetching code" ("How Netflix Scales its API with GraphQL Federation (Part 1)", 2020). N device BFFs means N implementations of "is this video playable". A schema means one. |
The Selection Set Is the BFF's Pruning Step
Step 8 of the 2012 PS3 walkthrough was "retrieves the wanted (and prunes out the unwanted) elements". In GraphQL that step moves into the client's query. The TV and the phone send the same schema different selection sets and different arguments:
The TV home page query (40 × 75 is illustrative, not a published Netflix figure)
query TvHome {
me { avatar { url } plan { tier } } # header: branches 1-2 on member 42
homePage {
rows(first: 40) {
title
videos(first: 75) {
title # branch 3: member 42 language
isPlayable # branches 4-5: entitlements, plan
artwork(width: 342, height: 192) { url }
bookmark { positionSeconds }
}
}
}
}This moves only the shape decision. The phone sends rows(first: 10) and a smaller artwork, and no server code changes. But three other things a BFF did are still undecided: which 40 rows, whether this device can play 4K, and what to show when personalization is down. They are policy, not shape, and a selection set can't express them. The Where the BFF's jobs go part follows each one to wherever it lands.
Execution: A Tree of Resolvers
The spec defines execution field by field. For a query, "the executor can execute the entries in a grouped field set in whatever order it chooses (normally in parallel)". This is allowed because non-mutation fields "must always be side effect-free and idempotent". Top-level mutation fields, by contrast, "should be executed serially". Each field has a resolver: a function from the parent object to that field's value. When a resolver returns an object, its sub-selection runs against that object. When it returns a list, the sub-selection runs once per item. That last rule is where the cost hides:
TvHome resolver tree (naive resolvers: each one calls its service directly)
Query.me ----------------------------------------------- 1 call (profile svc)
Member.avatar, Member.plan --------------------------- 2 calls
Query.homePage ----------------------------------------- 1 call (personalization)
Page.rows(first:40) ---------------------------------- 1 call -> 40 Row
Row.videos(first:75) x40 rows ---------------- 40 calls -> 3,000 Video
Video.title x3,000 -> catalog + member.language 6,000 calls
Video.isPlayable x3,000 -> entitlements + plan 6,000 calls
Video.artwork x3,000 -> image svc 3,000 calls
Video.bookmark x3,000 -> viewing history 3,000 calls
-------------------
~18,000 calls, and
member 42 alone is fetched ~9,000 timesThis is the N+1 problem: one call returns N parents, then N more calls fetch a child for each parent. Here it compounds across three list levels. It isn't a bug in anyone's resolver. It is what "each field resolves independently" means. Netflix's Kavitha Srinivasan, on the InfoQ podcast (2021): "GraphQL inherently does come with the N+1 problem."
DataLoader: Batch Within a Window, Memoize Within a Request
DataLoader (open-sourced by Facebook in September 2015) is "a port of the 'Loader' API" Facebook built in 2010 underneath its Ent framework. Haxl, Facebook's Haskell library, is built on the same idea. It gives each resolver a load(key) that returns a promise. Resolvers stay independent. The loader coalesces their calls:
| Batching | graphql-js DataLoader: "coalesce all individual loads which occur within a single frame of execution (a single tick of the event loop)". Then it calls your batch function once with every key. Tune with maxBatchSize and batchScheduleFn. |
|---|---|
| Memoization | ".load() is a memoized function." A second load(42) in the same request gets the same promise back, whether it comes in the same tick or much later. Tune with cache, cacheKeyFn, cacheMap, clear(key), prime. |
| Scope | One instance per request, by design: "Avoid multiple requests from different users using the DataLoader instance." It "does not replace Redis, Memcache, or any other shared application-level cache." |
| Contract | The batch function must return an array "the same length as the Array of keys", in the same order. Missing keys become null or an Error at their index. |
✗ Naive — one call per parent
Video: {
title: async (video, _, ctx) => {
const m = await profileSvc.get(ctx.memberId); // x3,000
return catalogSvc.title(video.id, m.language); // x3,000
},
}✓ Loader — one call per key set per window
// created per request, passed in context
ctx.loaders = {
member: new DataLoader(ids => profileSvc.batchGet(ids)),
title: new DataLoader(ks => catalogSvc.batchTitles(ks),
{ cacheKeyFn: k => `${k.id}:${k.lang}` }),
};
Video: {
title: async (video, _, ctx) => {
const m = await ctx.loaders.member.load(ctx.memberId); // 1 fetch total
return ctx.loaders.title.load({ id: video.id, lang: m.language });
},
}With loaders, TvHome costs roughly one backend call per field type per level: page, rows, one batched videos call, one batched titles call, one batched artwork call, one batched bookmark call. Member 42 is fetched once in total, no matter how many branches ask for it. If the image service caps batch size, a 3,000-key batch splits into several calls. The count is still set by the query's depth, not by N.
When "the same window" actually happens
A common simplification says GraphQL executes "breadth-first, one level at a time", so every load at a level lands in one batch. That describes one engine, not GraphQL:
| Engine | What sets the batch window | Consequence |
|---|---|---|
| GraphQL spec | Nothing. It allows any order, normally parallel. | Batching is an implementation property. Never assume it from the spec. |
| graphql-js + DataLoader | The event loop. By default the batch runs after the current promise jobs settle (enqueuePostPromiseJob). | Execution is not level-synchronized: a subtree starts as soon as its parent resolves. All 3,000 Video.title loads land in one tick only because each Row.videos list completes all its items together. Two same-depth fields under parents that resolve at different times give two batches. Memoization still prevents a second fetch of the same key. (Reasoned from graphql-js's completeValue path; not a documented guarantee.) |
| graphql-java + java-dataloader | The engine. With AsyncExecutionStrategy, graphql-java counts outstanding fields and calls dispatch() "as each level of the graphql query is executed". | This really is per level. But the docs warn it "can only optimally calculate DataLoader dispatches on a per-level basis", not across levels. Chained loaders (one loader called inside another's result) were dispatched automatically only from graphql-java 25.0, and only with enableDataLoaderChaining(true). Other strategies such as ExecutorServiceExecutionStrategy give caching but no batching. |
This matters for Netflix specifically. DGS is built on graphql-java (see Netflix's actual path), and Netflix's 2020 federation post describes the engine as orchestrating "the calls to the resolvers in a breadth-first traversal". So "per level" is the right model for a Netflix subgraph. It is not the right model for a Node subgraph, and it tells you nothing about the gateway, whose plan is a different structure (see The query planner).
DataLoader vs. Hystrix: The Same Two Ideas, Relocated
The Netflix Architecture guide's Hystrix part covers Hystrix's two "not isolation" features. DataLoader is both of them, reorganized:
| Hystrix request cache | HystrixCollapser | DataLoader | |
|---|---|---|---|
| Removes | Repeat calls for the same key | Many single calls → one batch call | Both, in one object |
| Window | The whole HystrixRequestContext | A timer: timerDelayInMilliseconds, default 10; maxRequestsInBatch default Integer.MAX_VALUE | Memo: the whole request. Batch: one tick (JS) or one level (Java) |
| Latency cost | None | Up to the window. Hystrix's own docs: a 5 ms command can take 15 ms worst case, "median penalty is half the window" | ~None by default: it dispatches when the executor runs out of work, not on a clock |
| Scope | One request (ThreadLocal context) | Per request, or GLOBAL across all users' threads in the JVM | One request (explicit context object). No global mode, on purpose |
| Failure handling | Fallback lives in the command | Fallback lives in the batch command | None. A per-key Error, which becomes a GraphQL field error and a null (see Where the BFF's jobs go) |
| Boundary | One process. None of the three sees a duplicate that another JVM or Node process fetches. A gateway doesn't share a subgraph's loaders, and subgraphs don't share each other's. The Router's own dedupe works at runtime, over the representations within one fetch node (see The query planner). Inside the subgraph, the reference resolver still runs once per key, so every subgraph still needs its own DataLoader. |
The important difference is in the "Window" row. Hystrix needed a timer because the calling code was arbitrary Java with no knowledge of what else was coming. A GraphQL executor has the query in hand, so it knows when a level or a tick is exhausted. It can batch with no added latency. Keep four windows apart. The Hystrix collapser batches within a 10 ms timer. DataLoader batches within a tick or level, and memoizes for the whole request. The federation planner is static: it plans from the query's shape and never sees values such as member 42. The Router dedupes at runtime, but only within one fetch node. Every one of them stops at a process boundary it doesn't own (see The query planner).
Falcor vs. GraphQL
| Falcor (Netflix, 2015) | GraphQL (Facebook, 2015) | |
|---|---|---|
| Client asks for | Paths into one virtual JSON object: lolomo[0..1][0..9].title | A selection set against typed fields, with arguments |
| Contract | Route patterns matched at runtime; no types, no introspection | A schema; queries validated before execution; introspectable |
| Graph identity | Built into the wire format: $type: "ref" and identity paths, one copy per entity | Not in the wire format. Responses repeat objects; client caches normalize by type + id |
| Batching and dedupe | In the client Model (batches gets, dedupes in-flight paths) | In the server (DataLoader). Client-side dedupe of identical in-flight queries is a client-library feature, not part of GraphQL |
| Why Netflix moved | Not a performance verdict. The published reasons are ecosystem ("we don't have community support"), self-documentation and tooling (Srinivasan, 2021), plus Studio having proven federated GraphQL, which let many teams own one graph (see The BFF era, Netflix's actual path). |
The Invariants
- Guarantees: Every request is validated against one typed schema before execution. The client's selection set fully decides the response's shape. Each field has exactly one resolver. With per-request DataLoaders, a key is fetched at most once per request per process, and calls for one field type in one batch window become one backend call.
- Does not guarantee: Any execution order or level-by-level batching (that is engine behaviour: per level in graphql-java, per tick in graphql-js). Dedupe across processes: the gateway, each subgraph and each backend service all fetch member 42 separately. A home for device policy as opposed to device shape. Freedom from N+1: the naive resolver is the default, and only a loader fixes it.