Unit 10 of 15 · about 5 hours · implement
Expand, migrate and contract changes, rollback boundaries and migration tests
State outlives code, so a deploy that only handles the new shape corrupts the old rows it meets. Expand-contract keeps every intermediate state readable by both versions until no old reader remains.
You'll be able to
- Plan an expand, migrate and contract change with a rollback point in each phase.
- Mark irreversible transformations and route them forward instead of rolling back.
- Test mixed-version migration with surge and availability limits plus sticky path routing.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Database migrations and expand-contractHLD Handbook - Reliability, Operations and Security at Scale
Database migrations and expand-contract
Read this section only here. The rolling, blue-green and canary sections belong to the previous unit.
- DDIA 2e Chapter 5: dataflow through databasesDDIA 2e - Chapters 2, 5 and 14
Chapter 5, Modes of Dataflow: Dataflow Through Databases (pp. 178-179); Event-Driven Architectures (pp. 189-191), especially preserving unknown fields during republishing
Read for mixed-version dataflow and preserving unknown fields; use the HLD migration section for the phased change itself.
- The Migrator: schema and data migration drillsBuilding Distributed Systems - The Tracer, The Securitor and The Migrator
First three free tasks of the track (schema migrations, expand and contract, zero-downtime change), graded in the browser after login
Treat a pass as a drill. Your evidence is the migration plan and rollback test on your own data.
Focus on
- During expand and migrate, keep every supported reader and writer compatible and keep both representations equal through an atomic update or a tested reconciliation. Contract ends compatibility with old binaries, so document that rollback boundary.
- Contract only after the last old reader is gone. Dropping a column while one old binary still selects it turns a cleanup into an outage.
- Once the last recoverable original is destroyed by hashing, deletion or lossy recoding, restoring the old shape needs a retained source or backup. A minimum software version stops insecure code rollback; it cannot invert the data transform.
- Rolling replacement respects fleet limits: total instances stay within surge, and available capacity never drops below the unavailability bound.
Common mistakes · 3
- Migrating before expanding. Backfilling the new column before all writers know it means old writers keep writing the old shape over migrated rows.
- Ignoring
maxUnavailablewhen stopping old instances. An old instance may stop whenever the remaining ready count stays at leastdesiredReplicas - maxUnavailable; only withmaxUnavailable = 0must ready replacement capacity come first. - Routing by shortest prefix. The strangler router takes the longest matching prefix, and the
/rule matches everything as the fallback.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Where is the rollback point of the migrate phase?Answer
At the dual-shaped state, before contract. Roll readers back only after verifying the old representation holds every acknowledged write; if new writers updated only the new column, switching back loses those writes.
2.A migration hashes raw identifiers into buckets. Why can it not roll back?Answer
Hashing is irreversible: the bucket does not determine the identifier. Restoring the old shape needs a retained copy of the originals or a backup; otherwise recovery rolls forward with a fix.
3.Desired 3, surge 1: how many instances may exist at once, and when may an old instance stop?Answer
At most 4. An old instance may stop whenever the remaining ready count stays at least
desiredReplicas - maxUnavailable. WithmaxUnavailable = 1one old instance may stop before any new one is ready; with 0 a ready replacement must come first.4.Rules exist for
/apiat 30% and/api/v2at 100%. A request for/api/v2/ordersfrom a bucket-80 subject routes where?AnswerNew. The longest prefix
/api/v2wins over/api, and 80 is below 100. Percentage 0 always routes legacy, 100 always routes new.
Practice
- AlgoMaster: Route a Sticky Strangler Rollout
Longest-prefix match with
/as catch-all; the pinned hash decides buckets andbucket < rolloutPercentroutes newThen apply the same routing to your loglab migration. The section mini-project covers this: mixed-version migration and rollback tests on existing data.
- AlgoMaster: Audit a Rolling Deployment Trace
Surge and unavailability limits on every event; unknown events violate; a valid partial trace is not complete
You're done when
Your three-phase plan names every rollback point, both auditors pass including the partial-trace case, and a hashing transform is marked roll-forward-only.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 14 more in the section
- HLD Handbook - Reliability, Operations and Security at ScaleHLD Handbook · primary
Read Part 6 observability, SLOs, resilience, overload, deployments, chaos, incidents and health, then Part 7 authentication, mTLS, secrets, tenancy and data governance chapters relevant to the capstone. Skip unrelated case studies.
- DDIA 2e - Chapters 2, 5 and 14Martin Kleppmann and Chris Riccomini · support
Use Chapter 2 "Describing Performance" for percentile and response-time vocabulary and Chapter 5 for compatibility during rolling upgrades. Chapter 14 is about predictive analytics, privacy and data governance, not operations: read its "Privacy and Tracking" section for the retention and deletion units.
- Building Distributed Systems - The Tracer, The Securitor and The MigratorBuild Distributed Systems · optional
Only the first three tasks of each track are free: in The Tracer, trace-context propagation, span lifecycle and a collector; in The Securitor, JWTs, the OAuth 2 code flow with PKCE and sessions; in The Migrator, schema migrations, expand and contract, and zero-downtime change. Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.
Also in this section
- Google SRE Books - SLOs, Monitoring, Overload, Cascades, Incidents and RecoveryGoogle · required
Read SRE Chapter 4 (service level objectives), 6 (monitoring distributed systems), 21 (handling overload), 22 (addressing cascading failures), 14 (managing incidents) and 15 (postmortem culture); Workbook Chapter 2 (implementing SLOs) and 5 (alerting on SLOs); and Building Secure and Reliable Systems Chapter 5 (least privilege) and 9 (design for recovery). Convert each into one alert, limit, load test or runbook action in the capstone.
- Metastable Failures in Distributed Systems (Bronson et al., 2021)HotOS · support
Read the trigger and sustaining-effect model of metastable failure and the retry and shedding design prompts. Its model illustrates; it does not predict.
- Metastable Failures in the Wild (Huang et al., 2022)USENIX OSDI · support
Read the incident study for how retries and load sustain outages after the trigger ends; it is a sample of public reports, not a rate.
- Simple Testing Can Prevent Most Critical Failures (Yuan et al., 2014)USENIX OSDI · support
Read the findings on error-handling code and how few nodes and events reproduce most failures, as the case for testing error paths in your campaign. Its bounds come from one sample of 2014 systems.
- Gray Failure: The Achilles' Heel of Cloud-Scale Systems (Huang et al., 2017)Microsoft Research · support
Read the gray-failure model (differential observability between a detector and its clients) as vocabulary for telemetry and failure detection.
- The Internals of PostgreSQL - Base Backup and Point-in-Time RecoveryHironobu Suzuki · support
Read Chapter 10 (base backup, how PITR replays WAL, timelines and incremental backup) as the real-engine model for backup integrity, recovery points and restore verification. Note the date you read it.
- SPIFFE Workload Identity and Workload APISPIFFE Project · support
Read the SPIFFE ID, X.509-SVID and trust bundle specifications and the Workload API (
FetchX509SVID,FetchX509Bundles) to design service identity, short-lived credentials and bundle rotation. A local mock is sufficient unless a real SPIRE deployment answers a specific gap. - OpenTelemetry Signals and Semantic ConventionsOpenTelemetry · support
Read signals and context propagation (W3C Trace Context
traceparent, inject and extract, baggage rules), then the semantic conventions (1.44.0) for the RPC and messaging areas with their stability status. Define bounded attributes for request, node, partition, term and offset identities, and never infer global order from display timestamps. - Replicated Log and Stream Processor - Production ContractRoadmap-Final · support
Add workload identity, tenant checks, audit, SLOs, capacity limits, backup and verified restore, mixed-version migration, rollback and reduced point-in-time ML data paths. Run one compound incident from detection through recovery.
- OWASP Threat Modeling Cheat SheetOWASP · reference
Use System Modeling (data-flow diagrams, trust boundaries, stores and processes), Threat Identification (the STRIDE table applied to components, data flows and trust boundaries) and Response and Mitigations to build the unit threat model.
- Feast Documentation - Point-in-Time Joins and Feature RetrievalFeast · support
Read Point-in-time joins (entity dataframes,
get_historical_features, TTL backward scan,filter_by_created_timestamp) and Feature retrieval (event_timestampas the inclusive upper bound,get_online_featureswithout timestamps, feature services per model version, materialize refresh). Work the join logic on tiny local tables; do not deploy Feast. Page read 2026-10-15 (v0.66-branch documentation). - MLflow Model Registry DocsMLflow · support
Read the Model Registry page (registered models, versions, lineage to the producing run, aliases such as @champion, and tags) and the registry tutorial promotion flow. Stages are deprecated since MLflow 2.9; use aliases and tags. Page read 2026-10-15; the versioned docs move, so re-pin the version you read.
- DVC Docs - Data VersioningDVC · support
Read
dvc add(Description and Example: Single file) for.dvccontent-hash sidecars, thedvc.yamlpage with itsdvc.lock filesection for pipeline state, andpushandpullfor transfer. A local directory remote is enough; do not set up cloud storage. Page read 2026-10-15. - PostgreSQL 18 Documentation - Recovery Targets, Backup Verification and RewindPostgreSQL Global Development Group · reference
Read Section 19.5.6 Recovery Target, the
pg_verifybackupreference and thepg_rewindreference for recovery stopping points, manifest checks and rejoining a diverged primary.