The Migration Playbook: A Worked Example
The Starting Point
This is the TV home page as the running example has it. Netflix's published migration covers the iOS and Android apps (see Netflix's actual path). This TV version is our extrapolation of that path, not Netflix's documented TV code:
TV BFF, GET /tv/home?profileId=42 (orchestration, abridged)
member = memberSvc.get(42) // maturity, language, avatar
plan = membershipSvc.plan(42) // plan, entitlements
page = personalizationSvc.homePage(42, device=TV, rows=40, perRow=75)
page = page.filter(v -> v.maturity <= member.maturity && plan.allows(v))
videos = catalogSvc.batchGet(page.videoIds) // title, rating, runtime
art = artworkSvc.batchGet(page.videoIds, 1280x720, locale=member.language)
marks = viewingHistorySvc.bookmarks(42, page.videoIds)
return shapeForTv(page, videos, art, marks) // one device-specific JSON blobBefore migrating anything, sort every line of that script into one of three bins. This is the organizing line of the guide applied to the migration plan. Entity lines (memberSvc.get, catalogSvc.batchGet) belong to a subgraph. Screen lines (rows=40, perRow=75, 1280x720, shapeForTv) belong to the client's selection set, field arguments or a page-composition layer. The filter line belongs to neither. It is a business rule that joins two entities (member maturity × video maturity, plan × entitlement), and today it lives in the BFF only because the BFF was the one place that could see both. The playbook moves the first bin and the second bin, and it must not lose the third along the way (the second trap below). Where each bin ends up is see Where the BFF's jobs go.
Phase 0: Design the Contract and the Parity Oracle
There are two decisions to make before writing a resolver. First, what schema does the shim expose? Once a TV app version ships with a query against it, that schema is a contract you can only change through deprecation (see Schema governance). Netflix's Video API had to reproduce the shim's behaviour exactly, including "empty or null" quirks (see Netflix's actual path). So the shim should expose the target entity schema, not the BFF's JSON shape. Member, Video, Row and Page should be real types with @keys from day one, even though a single process resolves all of them. Second, what counts as "same"? Write down the parity oracle for each field now (the table in Phase 3). Otherwise the first replay run produces a thousand diffs and nobody knows which ones matter.
Phase 1: A Router and One legacy Subgraph
Stand up the router with a supergraph made of exactly one subgraph, legacy. It is a GraphQL service (a DGS, in Netflix terms) whose resolvers call the BFF's existing orchestration functions:
legacy subgraph SDL (tv-shim:4000): the target shape, all resolved by one process
extend schema @link(url: "https://specs.apollo.dev/federation/v2.7", import: ["@key"])
type Query { homePage(profileId: ID!): Page }
type Page { member: Member! rows: [Row!]! }
type Row { id: ID! title: String! videos(first: Int = 75): [Video!]! }
type Member @key(fields: "id") {
id: ID!
maturityLevel: MaturityLevel
language: String!
avatar: Avatar
plan: Plan!
entitlements: [Entitlement!]!
}
type Video @key(fields: "id") {
id: ID!
title: String!
maturityRating: String
artwork(width: Int!, height: Int!): Artwork # device policy becomes an argument
bookmark: Bookmark # null = never watched
}supergraph.yaml (rover supergraph compose) and router.yaml
federation_version: 2
subgraphs:
legacy:
routing_url: http://tv-shim:4000/graphql
schema: { file: ./legacy.graphql }
---
traffic_shaping:
subgraphs:
legacy: { timeout: 1500ms } # the BFF's own p99.9 plus headroom; see trap
include_subgraph_errors:
all: true # internal clients only; see §8At this stage every query plan is a single Fetch(service: "legacy"). There are no entity hops and nothing is joined. This phase proves only the router tier: added latency (Netflix measured about 10 ms worst case for its gateway in 2020, see Operating the gateway), deployment, and whether observability works end to end. Rollback: none is needed, because no client points at it yet.
Phase 2: Clients Switch Protocol, Measured by an AB Test
The TV app ships a GraphQL client behind a feature flag. The flag is allocated by the AB platform, and Netflix's Phase 1 used 1M users across two cells. The treatment cell sends one operation:
query TvHome($profileId: ID!) {
homePage(profileId: $profileId) {
member { id language avatar { url } }
rows {
id title
videos(first: 75) {
id title maturityRating
artwork(width: 1280, height: 720) { url }
bookmark { positionSeconds }
}
}
}
}The server side has not changed. Both cells run the same orchestration code, so a payload diff here mostly shows mapping bugs in the shim. The larger risk is on the client: normalized-cache TTLs, pagination, error handling. That is why the test is an AB test on QoE (time to render, error rate, play starts per session), not a diff. Rollback: turn the flag off for the cell. Exit criterion: QoE is neutral or better at 100% of flag-capable app versions. The REST endpoint stays live, because older TV app versions can't read the flag and will keep calling /tv/home (the third trap).
Phase 3: Carve Out Entities, One Field at a Time
Now the server side changes. Choose the order by how easy parity is to check and how many hops the move adds:
| # | Field(s) moved | From → to | Why this position |
|---|---|---|---|
| 1 | Member.maturityLevel, language, avatar | legacy → members | Pure lookups with exact-match parity. The move adds one entity hop at depth 1 |
| 2 | Member.plan, entitlements | legacy → membership | Exact match, but these gate playback. Move them only after #1 has proved the tooling |
| 3 | Video.title, maturityRating | legacy → catalog | A batch of up to 40×75 representations in a single _entities call, so catalog needs a DataLoader (see Federation's model) |
| 4 | Video.artwork, Video.bookmark | legacy → artwork / viewing-history | Personalised or time-varying. The parity oracle is an invariant, not equality |
| 5 | Query.homePage, Page, Row | legacy → personalization | The root, moved last. The maturity/plan filter has to go with it (the second trap) |
Step 1 uses the same SDL as see Federation's model. The members team deploys its subgraph with the field and a label:
type Member @key(fields: "id") {
id: ID!
maturityLevel: MaturityLevel @override(from: "legacy", label: "percent(5)")
}For the 5% of requests that get the label, the plan gains a sequential step, because the Member reference comes from legacy's response. This is the price of moving a field out while its parent stays behind. (Illustrative plan, Apollo's text format. The query planner part covers how this interacts with the other four member-42 needs.)
QueryPlan {
Sequence {
Fetch(service: "legacy") {
{ homePage(profileId: $profileId) { member { __typename id language avatar { url } }
rows { id title videos { id title ... } } } }
},
Flatten(path: "homePage.member") {
Fetch(service: "members") {
{ ... on Member { __typename id } } =>
{ ... on Member { maturityLevel } }
},
},
},
}Make the rollout sticky. percent(5) is rolled per request (The Federation's model part's trap), so member 42 would switch between implementations from one refresh to the next. That is the wrong behaviour for a field that gates what a kids profile sees. Use a custom label instead, and let the edge decide who is in the cohort, the same way Netflix's Sticky Canary let Zuul bucket-hash device + profile:
Illustrative: Zuul sets a stable bucket; a router Rhai script turns it into a label
# members subgraph
maturityLevel: MaturityLevel @override(from: "legacy", label: "members-maturity")
// router Rhai (sketch: check your router version's Rhai API)
fn router_service(service) {
service.map_request(|request| {
let bucket = parse_int(request.headers["x-rollout-bucket"]); // 0..99, hash(profileId) at Zuul
if bucket < 5 {
request.context["apollo::progressive_override::labels_to_override"] = ["members-maturity"];
}
});
}| Lever | Scope | Speed |
|---|---|---|
| Lower the bucket threshold (a Zuul/Rhai config value) | One label (can cover several co-migrated fields) | Config push, with no schema publish |
Republish members with a lower percent(n), or without @override | One field | Composition + router hot-reload |
| Route the whole cohort to a baseline router fleet with the old supergraph | Everything in that release | Zuul weight. This is Netflix's Sticky Canary shape (see Netflix's actual path) |
What "parity" means for a personalised payload
Netflix's replay tester sampled real requests (from Mantis), ran each query against the old and the new implementation, and diffed the results as flattened JSON paths. On a personalised page, two runs of the same implementation already differ: the recommender re-ranks, artwork is chosen per member, and bookmarks move. So the replay has to hold inputs fixed, and each field needs its own oracle:
- Pin what you can. Replay both variants at the same moment, with the same AB-cell allocations, locale and device headers. Force the label on one replay and off the other (the label-forcing header is the reason for using a custom label). If personalization exposes a snapshot or request ID, pass the same one to both.
- Classify each field. Exact:
maturityLevel,plan,title,maturityRating. Invariant (for fields that can't be pinned): same set of row IDs and videos per row, every video playable underentitlements, nomaturityRatingabovematurityLevel, artwork URL present and the right size. Tolerance:bookmark.positionSecondswithin the heartbeat interval. Excluded: impression-logging side effects, mutations, PII (Netflix excluded PII from replay too). Behaviour on these is checked by the sticky canary's QoE metrics. - Normalize, then set a diff budget. Decide ahead of time whether
nulland[]are equal, and set the float and date precision. Netflix's replay found encoding, localization, date-precision and float differences, plus missing IDs from "over-eager timeouts". The step is done when diffs in the exact class are zero and every remaining diff has a named, accepted cause.
/data/homePage/member/maturityLevel: (TEEN, TEEN) ok
/data/homePage/rows/3/videos/12/maturityRating: ("TV-14", null) catalog timeout: tune
/data/homePage/rows/*/id: set-equal invariant okPhase 4: Delete
- Per field, at 100%: delete the field from
legacyfirst, then drop@overridefrom members. That order is safe because the router already ignores legacy's copy (Apollo migrate-fields docs). Remove each label as soon as it reaches 100%. Every live label on the home operation's path doubles the number of plans for it (see Federation's model). - Legacy subgraph: once step 5 has moved
Query.homePage,legacyresolves nothing. Take it out ofsupergraph.yaml, then delete the service. - REST endpoint: delete it only when per-client-version usage stats show traffic below the floor you've agreed on. Then put the remaining screen logic (
rows=40, perRow=75, the artwork size) where The Where the BFF's jobs go part puts it. The TV query already passesfirst: 75andwidth: 1280as arguments. Row count, if it isn't a client argument, needs an owner.
| Phase | Variable changed | Parity test | Rollback |
|---|---|---|---|
| 1 Router + legacy | New tier, with no client traffic | Synthetic load, trace completeness | None needed |
| 2 Client protocol | REST → GraphQL, same server logic | AB test on QoE | Feature flag off |
| 3 Field ownership | One field's resolver | Replay diff + sticky cohort QoE | Bucket threshold → percent republish → baseline router fleet |
| 4 Delete | Removal of dead paths | Field and client-version usage stats | Re-add the field. Keep the previous supergraph available (see Operating the gateway) |
The Invariants
- Guarantees: Each phase changes one variable and has a rollback that doesn't need a client release. With a custom label driven by a stable bucket, a member sees one implementation of a field for the whole experiment. Once the field has been deleted from
legacyand the@overrideremoved, exactly one subgraph resolves it. - Does not guarantee: That a field-by-field replay catches bugs between fields, such as a rule that joins maturity and rating. That a personalised payload can be compared for exact equality. That moving a field makes the page faster, since each carved field whose parent stays in
legacyadds a sequential hop. That member 42 is read fewer times, because reads hidden inside resolvers stay invisible to the planner until they are expressed in the schema. That the BFF can be deleted when the GraphQL rollout reaches 100%.