Lesson 5 of 9 · 28m
Migration Tooling and Compatibility Shims
Build adapters, translation layers, migration CLIs, fixture generators, and dual-run validation that reduce client switching risk.
The difference between a migration document and migration tooling is empathy implemented in code. Documents ask every customer to repeat the same translation work. Tooling does the translation once, validates it, and makes the safe path easier than improvisation. Compatibility shims are not a failure of elegance; they are how production systems change without demanding synchronized perfection from strangers.
Put translation at a deliberate boundary
A shim converts old requests and responses into the new domain model. It belongs at the API boundary, where validation, observability, and version negotiation are centralized:
def v1_invoice_response(i: Invoice) -> dict:
return {"id": i.public_id, "amount_cents": i.total.minor_units,
"currency": i.total.currency, "user_id": i.owner_public_id,
"status": legacy_status(i.lifecycle_state)}The dangerous version is hundreds of conditionals scattered through business logic. That corrodes the new model and makes removal impossible because nobody knows which behavior belongs to which client.
Do not let the shim become the product
Compatibility code needs an owner, tests, metrics, and an expiration condition:
owner: payments-api team
removal condition: <2% of monthly active integrations for 30 days
telemetry: response header X-Acme-Compatibility: invoices-v1
tests: golden v1 examples generated from canonical v2 fixturesIf the shim cannot be removed, it is not a migration bridge. It is a second permanent API wearing a trench coat.
Build migration tools clients can run
Depending on the API, useful tooling includes SDK upgrade helpers, request converters, fixture generators, linters, and validation commands. A small CLI can answer the questions integrators actually have:
acme-migrate inspect --log requests.ndjson --api invoices
acme-migrate verify --base-url https://api.acme.dev --token "$TOKEN"Dual-run risky migrations
For high-risk behavior, let customers or internal teams compare old and new responses before cutover. A shadow mode records both outputs without exposing inconsistent behavior:
new_result = invoice_service_v2.get(invoice_id)
legacy_result = v1_invoice_response(new_result)
record_diff_sample("invoice_get_v1", legacy_result, v2_invoice_response(new_result))
return legacy_resultAt the client boundary, dual-run means sending equivalent requests to both versions in a test environment and diffing normalized output. Normalize timestamps, ordering, and unstable IDs before comparing or you will drown in false differences.
Preserve identity and idempotency across versions
A migration that changes object IDs, idempotency-key behavior, or webhook event correlation needs an explicit mapping strategy. Clients reconcile records across systems. If inv_123 becomes 01J9... with no stable alias, you have created a data migration incident disguised as an API refresh.
Field notes
- Log shim use with enough detail to identify integration owners, but avoid logging secrets or full payloads.
- Translate errors as carefully as success responses; retry logic often depends on error shape.
- Feature parity does not mean bug parity. Document intentional behavior corrections.
- Delete shim code when adoption reaches the removal condition, not when someone remembers it exists.
Was this lesson helpful?