Search Sreeni's Insights

Filter by content type
technical January 19, 2017 6 min read

Strangler pattern - migrating a legacy monolith step by step

The Strangler pattern provides a staged way to move capabilities from a legacy monolith behind a facade, while preserving contracts, controlling data ownership and reducing migration risk.

Share:

Strangler pattern - migrating a legacy monolith step by step

Legacy applications are rarely failing because every line is bad. They are failing because one large deployment is carrying many business capabilities, old dependencies and an increasing amount of risk. A fund platform may contain pricing, units, documents, factsheets and investor access in one monolith, and even a small change is requiring a complete release.

Last year, we discussed Angular 2 versus React and how front-end choices are affecting architecture. We also looked at microservices and their hidden costs. In this article, we are going to see how the Strangler pattern can help us migrate a legacy monolith step by step without attempting a risky rewrite.

TL;DR Summary

  • The Strangler pattern places a facade or routing layer in front of a legacy application.
  • New capabilities are carved out one by one while the old path continues to serve the remaining functions.
  • An anti-corruption layer protects the new model from legacy concepts and data shapes.
  • Data ownership must move deliberately; copying data without a consistency plan creates another monolith.
  • Feature toggles, observability and rollback are required for safe migration.
  • Stop when the remaining legacy capability is small, stable or cheaper to operate than replace.

Challenges

The rewrite trap

A complete rewrite looks clean on a diagram, but it is requiring the team to understand every hidden rule in the old system before delivering value. Fund price rounding, document naming and investor permissions may not be written in one place, and a rewrite is discovering them only after customers are using it.

One release boundary

When pricing and document generation are in one monolith, the team must release both even when only one capability changed. A defect in a new factsheet can block a price fix, and a deployment rollback is affecting unrelated functions.

Data coupling

The old application may allow every module to read every table. Extracting a service without deciding who owns fund facts, units or prices is creating two writers and inconsistent reports.

What is the Strangler pattern?

The Strangler pattern, also called Strangler Fig Application, is a migration approach where a new system gradually replaces parts of a legacy system behind a facade or routing layer.

In simple terms, new functionality is growing around the old application until the old path is no longer needed, similar to a strangler fig growing around a host tree. We are not deleting the monolith on the first day; we are reducing its responsibility in controlled slices.

The following diagram depicts the facade which routes requests to the legacy monolith or an extracted fund capability.

Strangler facade routing
Strangler facade routing

The purple path is a request for the extracted pricing capability. Other requests are still routed to the monolith, and the facade gives clients one stable front door.

Why the Strangler pattern is important?

The pattern is important because it is reducing migration risk and delivering value during the journey. Each extracted capability can have its own deployment, tests and operational ownership, while the remaining monolith is not being changed unnecessarily.

In our case, extracting fund factsheets may be safer than starting with pricing. Factsheets have a clear document boundary, while pricing may be connected to many batch and valuation processes. Choose the first slice from coupling, business value, risk and the team’s ability to observe it.

Migration stages

The following diagram explains the stages from one monolith to a smaller legacy core.

Strangler migration stages
Strangler migration stages

1. Map the current capability

List endpoints, jobs, database tables, external calls and owners. Draw the dependency graph for fund, units, prices, documents and investor channels. Find where the business transaction really ends, not only where a controller method begins.

2. Add the facade

Use a reverse proxy, IIS Application Request Routing (ARR) with URL Rewrite, an API gateway or another routing layer. The 2016 API Gateway article provides a useful front-door comparison. The facade must preserve the public contract while routing canary requests to the new service.

3. Choose one capability

Select a bounded capability such as document generation or fund factsheet retrieval. Keep the first extraction small enough to deploy and roll back, but meaningful enough to remove a real monolith dependency.

4. Add an anti-corruption layer

Legacy names are not always healthy domain names. A legacy FundMaster record may contain pricing, client and reporting fields together. Translate it into a new Fund and FundDocument model at the boundary, so the new service does not copy every legacy assumption.

5. Define data ownership

Choose one writer for each business fact. During transition, the new document service may read a replicated projection while the monolith remains the owner. Later, move the write ownership and publish a change event. Document the acceptable delay and reconciliation process.

6. Route and observe

Use a feature toggle or route rule to send selected traffic to the new capability. Record success rate, latency, errors and business outcomes. Start with internal users or a small fund group, then expand after the pulse check.

7. Remove the old path

After the new capability is stable, remove the old route, code, tests and data access. Source control is preserving history; commented legacy code is not a migration strategy. Continue to monitor clients for calls to the retired path.

Selection criteria and risks

DecisionChoose the safer path whenRisk to control
First capabilityBoundary is clear and independently testableHidden shared rules
Routing layerClients need one stable endpointFacade becomes another monolith
Data syncLegacy remains source of truth temporarilyStale or duplicate data
Feature toggleRollout must be gradualToggle is never removed
Anti-corruption layerModels have different meaningsMapping becomes too large

Feature toggles are useful for migration, but give every toggle an owner and removal condition. Refer the 2016 feature-toggle article for the broader safe-shipping guidance.

When should we stop?

The goal is not always zero legacy code. Stop extracting when the remaining functions are stable, low-risk and cheaper to operate than a new service. Continue when the monolith is blocking independent releases, scaling poorly or carrying a high change cost.

Measure the decision with deployment frequency, incident impact, lead time and the number of clients coupled to the old path. Use placeholders such as <before migration value> and <after migration value> when a real metric is not yet confirmed.

Must Do / Should / Don’t

Must Do

  • Must keep one stable facade while routes are changing.
  • Must define data ownership and reconciliation before adding a second writer.
  • Must add monitoring and rollback before expanding traffic.
  • Must remove retired routes and toggles after migration.

Should

  • Should start with a capability which has a clear boundary.
  • Should use an anti-corruption layer instead of copying legacy models.
  • Should migrate in small pull requests and keep the monolith deployable.

Don’t

  • Don’t rewrite the complete monolith before learning its hidden business rules.
  • Don’t extract a service while leaving two independent writers for the same fact.
  • Don’t create a facade which contains business logic for every team.
  • Don’t keep old code commented “for safety”; source control is the backup.

Wrap up

In this article, we have looked at the Strangler pattern, facade routing, capability extraction, anti-corruption layers, data ownership, feature toggles, observability and migration stopping criteria.

I really appreciate that you took the time to read this article. In the next article, I will walk you through the Backend for Frontend pattern for SPA and mobile applications.

Related Posts