A schema document can describe intended shape, but compatibility is an observed property of running consumers. A release matrix combines the oldest supported client, current client, intermediate server, and target server. Expand-contract migration first serves both shapes, then moves readers and writers, then removes the old shape after evidence. The intermediate state matters: a browser bundle and server rarely switch atomically across caches and regions. Contract tests should include behavior as well as types: status codes, null meaning, permissions, pagination, and how clients recover from an unknown value.
Consumer Contract Matrix and Expand-Contract Release
Working case
The case API moves reviewerName into reviewer.displayName. Release 47 reads reviewerName; release 63 reads the nested object. During rollout, region A has the expanded server while region B still has the old server. Release 63 must tolerate a missing nested field or wait until every region serves it. Later both server regions expose both fields. Only then can clients start reading the nested value. A late offline release-47 tab wakes after the new bundle deploys; its supported lifetime determines when reviewerName can be removed. A contract test checks both clients against both active server shapes before each step.
Implementation boundary
function releaseMatrixIsSafe(results) {
return results.every(row => row.supported && row.ownerVisible && row.permissionChecked);
}
console.log(releaseMatrixIsSafe([{ supported: true, ownerVisible: true, permissionChecked: true }, { supported: true, ownerVisible: false, permissionChecked: true }]));
// Output: falseBuild a matrix of supported client artifacts and server phases: old, expanded, reader-switched, contracted. Save representative request and response fixtures from actual routes, with private data replaced by synthetic values. Validate those fixtures against the declared schema, then run consumer behavior tests against route handlers or an isolated service. Include old and new authorization paths, null and missing values, unknown enum members, and a rollback after writes use the new form. When dual-writing, choose one canonical source and reconcile divergence; do not let two fields update independently forever. If a region can lag, hold reader switch until all regions pass the expanded contract. Gate contraction on client lifetime evidence, not on the latest deployment finishing.
Cost and boundaries
For C supported clients and S server phases, a full matrix has O(C × S) combinations. Keep it small by declaring support windows and focusing on boundaries that change, while still testing every supported artifact against every active server phase. Fixture drift is a risk: a schema-only mock can pass even when the real serializer differs. Running a few route-level contract tests costs more than a pure unit test but catches wiring errors. Dual-write logic adds storage and reconciliation cost, often O(N) across N migrated records. Measure contract failures by phase, field divergence, client release distribution, and rollback success.
Failure trace
The new client expects reviewer.displayName after region A deploys, but traffic reaches region B and the page shows an empty owner. Add an intermediate tolerant reader or wait for the complete expanded rollout. Next, dual-write reviewerName and displayName independently; two updates disagree, and rollback serves stale data. Select one canonical value and verify adapters agree. Finally, delete reviewerName after the latest release passes while a supported offline tab still needs it. Use the matrix and actual client lifetime to stop contraction until the old artifact is outside support.
Verification
- Each supported client is tested against each active server phase.
- Dual representations have one canonical writer and a divergence check.
- Rollback and region lag are included before contraction.
Practice drill
Create release-47 and release-63 client fixtures and three server phases for case 29. Run all six combinations for owner display, save permission, a missing nested object, and an unknown status. Simulate region A expanding before region B. Flip the canonical writer, roll back one release, and compare both representations. Record the exact migration gate for moving readers and for removing reviewerName. One matrix row should deliberately fail so the release gate proves it can stop deployment.
Decision note
A contract is ready when every supported client survives every server phase it may actually meet.
Common Mistakes
- Testing only newest client with newest server.
- Treating a schema diff as proof of runtime compatibility.
- Deleting an old field before offline and cached clients leave support.
Related lessons
API Contract Evolution and Client Migration; Response Shape Evolution and Unknown Values; API Version Selection and Representation Scope; Deprecation, Sunset, and Consumer Evidence; Tests across boundaries: assert behavior, not implementation text; Expand-and-Contract Schema Migrations.
Apply and check
Build Project: permit API client migration and review Web Development: API contract migration quiz.
