Microservices Strangler Fig Migration

Most teams do not start from a blank page. They own a large, aging application that earns money every day and needs a modern shape. Rewriting everything at once is slow and risky. The strangler fig pattern moves functions to microservices one piece at a time while the old system keeps running.

Layman Explanation

A strangler fig is a tropical vine. It sprouts on a tall tree, grows roots down the trunk, and spreads around the host. Years later the vine stands on its own and the old tree is gone. The migration pattern borrows the picture: a new system grows around the old one until the old one can be removed.

Diagram: Traffic Shifts Piece by Piece

STEP 1: Add a front door

 Users --> Routing layer --> Legacy monolith (everything)

STEP 2: Carve out one feature

 Users --> Routing layer --+--> New Reviews service
                           |
                           +--> Legacy monolith (the rest)

STEP 3: Keep going

 Users --> Routing layer --+--> Reviews service
                           +--> Search service
                           +--> Orders service
                           +--> Legacy monolith (small remainder)

STEP 4: Retire the monolith

The Migration Steps

Place a Routing Layer in Front

Put an API gateway or reverse proxy before the monolith. At first it forwards every request unchanged. This layer gives you control over which code answers which request.

Pick a Small, Valuable Slice

Choose a function with clear edges and modest risk, such as product reviews or email notifications. Early wins build confidence and teach the team new tools.

Build the New Service

Create the service with its own code and database. Copy or sync the needed data from the monolith.

Route Traffic Gradually

Send a small share of requests, such as five percent, to the new service. Compare results and error rates. Raise the share step by step until all traffic flows to the new service.

Remove the Old Code

Delete the legacy implementation after the new service proves stable. Dead code left behind confuses future developers.

Choosing What to Extract First

Good First CandidatesPoor First Candidates
Loosely connected featuresCore logic tangled with every module
Parts that change oftenRarely touched stable code
Parts with heavy loadFeatures with unclear ownership

Handling Data

Data causes the hardest part of any migration. Three approaches help:

  • Let the new service read from the monolith database through a temporary read-only link.
  • Copy data to the new database and keep both in sync with change events.
  • Move ownership fully, so the monolith calls the new service for that data.

Plan the final state early. Shared tables between old and new code should exist only as a short-lived bridge.

Anti-Corruption Layer

Legacy models often carry confusing names and odd rules. An anti-corruption layer translates between the old model and the clean new model. The new service stays tidy, and the translation code disappears with the monolith.

Risks and Safeguards

  • Run old and new paths in parallel and compare answers before switching.
  • Keep a quick switch that routes traffic back to the monolith.
  • Track progress with a visible list of extracted features.
  • Watch for a "distributed monolith" where new services still depend tightly on each other.

Key Takeaways

The strangler fig pattern replaces a legacy system through small, reversible steps. A routing layer controls traffic, gradual rollout limits risk, and careful data planning keeps the migration safe.