Skip to content

Lesson 7 of 9 · 25m

Evolving Architecture Without Big Rewrites

Use seams, strangler migration, parallel operation, and explicit rollback to change architecture while the business keeps shipping.

The big rewrite is usually a confession that the team lost control of gradual change. I have seen one succeed and many die quietly after consuming a year of roadmap. Architecture that survives is architecture that can be moved in slices while users keep using it. The goal is not to preserve old mistakes forever; it is to make replacement boring.

Find a seam before writing new code

A seam is a place where behavior can be diverted without rewriting everything: a route, an application service, a queue consumer, a repository interface, or a batch job entrypoint. Inventory behavior by caller and data ownership before choosing the seam.

route                 caller              state owned              extraction difficulty
GET /reports          internal dashboard  reporting projection     low
POST /checkout        storefront          cart + payment           high
POST /webhooks/stripe stripe              payment state machine    medium

Pick a seam with measurable value and limited blast radius. "Users" is not a seam; it is the whole system.

Strangle behavior, not syntax

The strangler pattern routes selected traffic to the new implementation while the old one remains authoritative or available for rollback. Route by tenant, percentage, feature flag, or specific workflow.

def checkout_handler(request, flags, legacy, replacement):
    if flags.checkout_v2_enabled(request.organization_id):
        try:
            return replacement.checkout(request)
        except ReplacementUnavailable:
            if flags.checkout_v2_shadow_only(request.organization_id):
                raise
    return legacy.checkout(request)

That sketch is not a license to catch-and-hide architectural failure. Define whether fallback is safe. In a write path, falling back after a partial operation can duplicate work.

Use shadow traffic to compare behavior

For read-heavy or reproducible workflows, run the replacement in parallel and compare outputs before making it authoritative.

1. send 100% requests to legacy
2. mirror 5% to replacement asynchronously
3. compare status, body shape, invariants, and latency
4. alert on semantic mismatch, not formatting noise
5. switch authority only after mismatch rate is understood

Canonicalize timestamps, floating point noise, and ordering before comparison. Otherwise you will spend the migration debugging irrelevant diffs.

Data migration is the real migration

Moving code is easy compared with moving truth. Decide whether the old system remains write-authoritative, the new system becomes authoritative, or both write with a synchronization bridge. Dual writes are a temporary risk, not a target architecture. If you use them, record ordering and reconciliation behavior.

CREATE TABLE migration_watermarks (
    migration_name text PRIMARY KEY,
    source_cursor text NOT NULL,
    target_cursor text NOT NULL,
    updated_at timestamptz NOT NULL DEFAULT now()
);

Backfill in resumable batches. Validate counts and sampled invariants. Keep rollback distinct from roll-forward: sometimes the only safe rollback is to stop writes, repair, and re-cut traffic.

Retire the old path explicitly

A migration is not finished when the new path works. It is finished when old endpoints, flags, fallback branches, compatibility shims, and zombie data paths have deletion dates. Half-migrated systems are worse than old systems because every incident now requires two mental models.

Field notes

  • Do not migrate and redesign the domain model at the same time unless the old model is the reason for migration. One big variable at a time.
  • Feature flags are operational debt. Expire them and remove branches.
  • Parallel run results are evidence only when inputs and authorization context match.
  • Keep a written authority matrix during migration: which system owns each field at each stage.
  • If rollback requires restoring production backups as the routine plan, redesign the cutover.

Was this lesson helpful?

Sign in to rate