How-To Guide

How to Implement the Strangler Fig Migration

Migrate incrementally with the strangler fig: route a slice to the new system, run both, and grow the new until the old is gone.

On this page

  1. Introduction
  2. Put a facade in front of the legacy system
  3. Migrate one slice at a time
  4. Run both and compare the results
  5. Switch the slice and keep the escape route
  6. Remove the old when the last slice moves
  7. Test the slice’s equivalence and the revert
  8. Common pitfalls
  9. Conclusion

Introduction

Replacing a legacy system is risky: a big-bang rewrite delivers nothing until the end, takes a long time, and a failed cutover leaves you with neither system fully working. The strangler fig pattern makes the migration incremental. A facade in front of the legacy system lets a new implementation grow one slice at a time, routing more traffic to the new as it proves itself, until the old system serves nothing and can be removed.

This tutorial implements a strangler fig migration: put a facade in front, migrate one slice at a time, run both and compare, and remove the old when it is empty. The examples use a routing facade, and the pattern applies to any incremental replacement.

Put a facade in front of the legacy system

The facade is the single entry point that the clients use, and behind it the legacy system and the new system coexist. The facade routes each request to the old or the new, so the migration is a routing decision rather than a cutover. The clients keep using the same entry point, so they are unaffected as the internals change.

The facade should route by a decision that can change per request, such as the path or a feature flag, so a slice’s traffic moves between the systems without a deploy. This is what makes the migration reversible: if the new system misbehaves for a slice, route that slice back to the old, and the clients never saw the difference. The facade is the switch that the migration is built on.

# the facade routes each request to the old or the new
/orders/*   -> new order service      (migrated slice)
/users/*    -> legacy monolith       (not yet migrated)
/payments/* -> legacy monolith
# a slice moves by changing the route, not by a cutover

Migrate one slice at a time

A slice is one endpoint, one feature, or one bounded context. Migrate one slice to the new system, verify it works, and leave the rest on the old, so each step is small and the system works after each. A small slice is easier to build, test, and revert, and the value is delivered incrementally rather than at the end.

Order the slices by the value and the risk: a high-value, low-risk slice first, to prove the approach and deliver early, and a high-risk or deeply coupled slice later, once the pattern is established. Each slice, when migrated, is verified and its traffic moves, and the old system’s role shrinks. The migration pace is set by the team, and the old system keeps serving the rest.

Run both and compare the results

For a slice, run the new and the old in parallel and compare their results before moving the traffic. Send the request to both, compare the responses, and log the differences, so a discrepancy is found before the users see it. This is the shadow traffic technique: the new system handles the request in parallel without serving the response, and its output is compared to the old.

Once the comparison shows the new matches the old for the slice’s traffic, switch the slice to serve the response. The comparison is the verification, and it is data-driven: the slice is migrated when the new is proven equivalent, not when it is believed to be. Keep the comparison running after the switch for a period, so a subtle difference is caught.

async function compareSlice(req) {
  const [oldRes, newRes] = await Promise.all([
    legacy.handle(req),
    newSystem.handle(req),
  ]);
  if (!equivalent(oldRes, newRes)) {
    metrics.incr('migration.mismatch');   // alert on a mismatch before the switch
    logger.warn({ req, oldRes, newRes }, 'slice mismatch');
  }
  return oldRes;   // the old serves until the new is proven
}

Switch the slice and keep the escape route

When the comparison is clean, switch the slice’s traffic to the new and keep the old available. If the new misbehaves, route the slice back, which the facade makes a configuration change. The escape route is what makes the migration low-risk: a slice can be reverted without a rollback deploy, and the users are unaffected.

Move the traffic gradually where the slice allows: a percentage of the traffic or a set of users, so a problem affects a small subset before the whole slice. Combined with the comparison and the escape route, the gradual move finds the edge cases while the blast radius is small. The old system’s data must still be migrated or shared for the slice, which is often the hardest part of the migration.

Remove the old when the last slice moves

The migration is complete when the last slice is moved and the old system serves nothing. At that point, remove the old system, so it is fully strangled rather than left running for a forgotten slice. A migration left half-finished leaves two systems to maintain, which is the worst outcome and a common one when the last slices are hard.

Track the slices and their status, so the remaining work is visible and the last few are not forgotten. The last slices are often the hard ones, deeply coupled or rarely used, and they are the ones that stall a migration. Keep them on the list and finish them, so the old system is removed and the migration’s benefit is realized.

Test the slice’s equivalence and the revert

Test that the new implementation matches the old for the slice’s traffic, using the comparison or a recorded set of requests. Test that the facade routes the slice to the new and reverts it to the old, so the switch works. Test that a mismatch is detected and logged, so the comparison catches a difference. These tests keep the migration verifiable and reversible.

# route the slice to the new and assert the responses match the old
node scripts/route-slice.mjs orders new
node scripts/compare-traffic.mjs orders   # assert no mismatch
# revert the slice to the old and assert it serves again
node scripts/route-slice.mjs orders legacy

Common pitfalls

A big-bang cutover instead of a slice-by-slice migration, no facade so the switch is a deploy, no shadow comparison so a difference reaches the users, no escape route so a slice cannot be reverted, and leaving the last slices unmigrated so the old system lingers are the recurring mistakes. A facade, a slice-by-slice move, a parallel comparison, a revert route, and a tracked list of the remaining slices address them.

Conclusion

The strangler fig migrates a legacy system incrementally. Put a facade in front, migrate one slice at a time and compare the results in parallel, switch the slice with an escape route to revert, and remove the old system when the last slice moves. Self-check by routing a slice to the new and asserting the responses match, and by reverting it and asserting the old serves. Then the replacement is continuous and reversible, not a risky cutover.

Sources: Martin Fowler: Strangler Fig pattern, Microsoft: Strangler Fig pattern, Paul Hammant: Strangler fig application.

FAQ

Why not a rewrite?
A big-bang rewrite delivers no value until the end, takes a long time, and risks a failed cutover. The strangler fig delivers value slice by slice, keeps the old system running throughout, and lets the migration stop at any point with a working system. It is lower risk and continuously deliverable.
How do I route a slice to the new system?
The facade routes by the request, such as the path, a feature flag, or a percentage of the traffic. Move one slice's traffic to the new, compare the results, and grow the share. The facade is the switch, so a slice can be reverted by routing it back to the old.

Related Examples