Checks: migration, backfills and cutovers
Templates for the four migration, backfills and cutovers stories. Unlike most checks, these run once per migration rather than on every commit, so write them as part of the cutover runbook, and make the runbook refuse to continue when one fails.
C-13: the newest revision wins, in either order
Section titled “C-13: the newest revision wins, in either order”- Proves: when a backfill and live replication write the same row, the target ends with the newest source revision whichever arrives last.
- Fails for: unconditional upserts. The backfill that overwrote a live update.
- Harness needs: apply a write through each path directly.
@ParameterizedTest@ValueSource(strings = {"live-then-backfill", "backfill-then-live"})void theNewestRevisionWinsWhateverTheArrivalOrder(String order) {
if (order.equals("live-then-backfill")) { live.apply(rev8); backfill.apply(rev7); } else { backfill.apply(rev7); live.apply(rev8); }
assertThat(target.customer("C-42").sourceRevision()).isEqualTo(8);}@pytest.mark.parametrize("order", ["live-then-backfill", "backfill-then-live"])def test_the_newest_revision_wins_whatever_the_arrival_order(order, live, backfill, target):
if order == "live-then-backfill": live.apply(rev8); backfill.apply(rev7) else: backfill.apply(rev7); live.apply(rev8)
assert target.customer("C-42").source_revision == 8-- Run after the backfill, with source and target revisions side by side.-- Any row returned is a target row older than its source.SELECT s.id, s.source_rev AS source_rev, t.source_rev AS target_revFROM source_customers sJOIN target_customers t ON t.id = s.idWHERE t.source_rev < s.source_rev;C-14: rollback keeps every acknowledged write
Section titled “C-14: rollback keeps every acknowledged write”- Proves: after cutting over, accepting orders and rolling back, every order a customer was told about exists exactly once in the old system and reaches its fulfillment run.
- Fails for: routing-only rollback. The rollback that lost successful orders.
- Harness needs: drive the router; read acknowledgements from the customer’s side (confirmation emails or captured payments).
@Testvoid rollingBackKeepsEveryAcknowledgedOrder() { router.cutOverTo(NEW_SYSTEM); var acknowledged = IntStream.range(0, 12) .mapToObj(i -> storefront.placeOrder(sampleOrder(i))) .filter(OrderResult::confirmed) .map(OrderResult::orderId) .toList();
cutover.rollBack(); // the real procedure, not router.switchTo()
for (var id : acknowledged) { assertThat(oldSystem.ordersWithId(id)).as(id).hasSize(1); } assertThat(oldSystem.nextFulfillmentRun().orderIds()).containsAll(acknowledged); assertThat(acknowledged).hasSameSizeAs(mailSink.confirmationsSince(router.cutOverAt()));}def test_rolling_back_keeps_every_acknowledged_order( router, storefront, cutover, old_system, mail_sink): router.cut_over_to("new") results = [storefront.place_order(sample_order(i)) for i in range(12)] acknowledged = [r.order_id for r in results if r.confirmed]
cutover.roll_back() # the real procedure, not a router flip
for order_id in acknowledged: assert len(old_system.orders_with_id(order_id)) == 1, order_id assert set(acknowledged) <= set(old_system.next_fulfillment_run().order_ids) assert len(acknowledged) == len(mail_sink.confirmations_since(router.cut_over_at))C-15: reconciliation compares by key
Section titled “C-15: reconciliation compares by key”- Proves: the cutover report names every wrong key with its signed difference, and shows the net difference that totals would have hidden.
- Fails for: counts and sums. The migration that passed reconciliation, which has a lab and a downloadable SQL script.
- Harness needs: load source and target tables.
@Testvoid theReportNamesSwappedValuesThatTotalsHide() { source.load(row("SKU-A", 7), row("SKU-B", 3)); target.load(row("SKU-A", 3), row("SKU-B", 7));
var report = reconciliation.compare("reservations", "sku");
assertThat(report.rowCountsMatch()).isTrue(); // the trap: this alone passes assertThat(report.differences()) .extracting(Difference::key, Difference::signedDifference) .containsExactlyInAnyOrder(tuple("SKU-A", -4), tuple("SKU-B", 4)); assertThat(report.netDifference()).isZero(); assertThat(report.passed()).isFalse();}def test_the_report_names_swapped_values_that_totals_hide(source, target, reconciliation): source.load([("SKU-A", 7), ("SKU-B", 3)]) target.load([("SKU-A", 3), ("SKU-B", 7)])
report = reconciliation.compare("reservations", key="sku")
assert report.row_counts_match # the trap: this alone passes assert {(d.key, d.signed_difference) for d in report.differences} == {("SKU-A", -4), ("SKU-B", 4)} assert report.net_difference == 0 assert not report.passed-- Every key that is missing, extra or different. Zero rows is the cutover gate.SELECT COALESCE(s.sku, t.sku) AS sku, COALESCE(t.reserved_qty, 0) - COALESCE(s.reserved_qty, 0) AS differenceFROM source_reservations sFULL OUTER JOIN target_reservations t ON t.sku = s.skuWHERE s.sku IS NULL OR t.sku IS NULL OR s.reserved_qty <> t.reserved_qty;C-16: coverage before agreement
Section titled “C-16: coverage before agreement”- Proves: a shadow comparison reports every eligible request, including those with no candidate response, and fails the release gate when coverage is below threshold.
- Fails for: matched-pairs reporting. The shadow test that missed the dangerous requests.
- Harness needs: feed the comparator a recorded hour of outcomes.
@Testvoid missingResponsesCountAgainstTheReleaseGate() { var hour = new ArrayList<ShadowOutcome>(); for (int i = 0; i < 950; i++) hour.add(matched(i)); for (int i = 950; i < 1000; i++) hour.add(candidateTimedOut(i, lineItems(240)));
var report = comparator.report(hour);
assertThat(report.eligible()).isEqualTo(1000); assertThat(report.matched()).isEqualTo(950); assertThat(report.candidateMissing()).isEqualTo(50); assertThat(report.coverage()).isEqualTo(0.95); assertThat(releaseGate.evaluate(report, minCoverage(0.99), minAgreement(0.999)).passed()).isFalse(); assertThat(report.missingRequests()).hasSize(50); // listed, so they can be replayed}def test_missing_responses_count_against_the_release_gate(comparator, release_gate): hour = [matched(i) for i in range(950)] + \ [candidate_timed_out(i, line_items=240) for i in range(950, 1000)]
report = comparator.report(hour)
assert (report.eligible, report.matched, report.candidate_missing) == (1000, 950, 50) assert report.coverage == pytest.approx(0.95) assert not release_gate.evaluate(report, min_coverage=0.99, min_agreement=0.999).passed assert len(report.missing_requests) == 50Related pages
Section titled “Related pages”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.