In brief
Strangler fig is a modernization approach in which you do not rewrite a legacy application all at once, but surround it with a new system and move functions over piece by piece. A facade sits in front of the old system and routes each request to the old or the new part. With every iteration the new part takes more traffic, until the old system can be switched off. The pattern lowers risk because every step can be checked and reversed, but it needs a plan for data and the discipline to actually remove old code.
How the pattern works
Martin Fowler popularized the name. A strangler fig sprouts on a tree branch, sends roots down to the ground and gradually surrounds its host, which eventually dies. In a system it looks like this:
- Facade. An intermediary goes in front of the old application: a proxy, an API gateway or a routing layer. At first it passes all traffic to the old system.
- New module. The team builds one function in the new system, for example handling returns.
- Cutover. The facade routes returns requests to the new module. Everything else still goes to the old application.
- More modules. The process repeats. The old system shrinks with every iteration.
- Decommissioning. Once nothing depends on the old system, it is switched off, and in the end the facade is often removed too.
| Rewrite from scratch | Strangler fig | |
|---|---|---|
| First business value | after everything is finished | after the first module |
| Cutover-day risk | all on one day | spread across many small steps |
| Rollback | hard or impossible | change the routing in the facade |
| Changes to the old system | frozen during the work | possible, though shrinking |
| Transitional cost | one system under construction | facade, data sync, two systems at once |
Step by step: from system map to switch-off
System map. Before the facade appears, the team lists the old application's functions, its entry points (screens, APIs, batch files, nightly jobs) and the tables each function uses. Without this map you cannot tell what can be cut out separately.
Facade. HTTP traffic is the easiest to intercept: an API gateway or reverse proxy sends `/zwroty` (returns) to the new service. Terminal screens, exchange files and batch jobs are harder. For those, the facade is often a message queue or a new file exchange point.
Anti-corruption layer. The new module often has to call functions not yet migrated, and old code has to call new code. Between them sits a layer that translates concepts and formats, so the new system does not inherit the old one's names and constraints.
Gradual cutover. Traffic is switched in stages: first the internal team, then one branch or 5% of customers, then everyone. Feature flags help here, because they let you return to the old path without a deployment.
Removing old code. Each iteration ends with deleting the migrated function from the old system, not just cutting traffic to it. Otherwise both systems grow at the same time.
How to choose the first module
| Criterion | Good candidate | Poor starting candidate |
|---|---|---|
| Boundaries | a function with its own tables and a clear entry point | logic spread across the whole database |
| Risk | read-only views, reports, catalogs | posting, settlements, balances |
| Rate of change | a module the business wants to change every month | a module nobody has touched in years |
| Visibility | an effect users can see | a change nobody will notice |
A good first module delivers a quick result and teaches the team the full cycle: facade, data, cutover, removal. The most critical logic moves later, once the cycle has been rehearsed.
Data: the hardest part
Functions are easier to cut out than data. A typical order for one domain, such as returns:
- New module on the old database. The new service reads and writes the returns tables in the old database. Only code changes.
- New database and sync. The returns tables are copied to a new database, and changes from the old one are carried over continuously with change data capture. The team compares data in both databases.
- Switching the source of truth. After validation, the new database becomes the only write location for returns. Only then are the old tables and procedures removed, because until that moment you can roll back.
The biggest mistake is dual writes from application code into two databases at once. When one write fails, the databases drift apart and nobody knows which is right. For each domain, at any moment, one database is the source of truth and the other gets a copy. A daily reconciliation report shows differences before users notice them.
Pitfalls and when the pattern does not fit
The most common pitfalls:
- A migration that never ends. Easy modules move quickly, hard ones stay for years, and the company runs two systems. The plan needs a date for switching off the old system.
- The facade as a bottleneck. All traffic passes through it, so it needs performance testing, redundancy and monitoring like any critical component.
- No comparison testing. The same case should give the same result in the old and new module. Comparing on production data catches differences in rounding, dates and statuses.
- A new system copying old mistakes. The anti-corruption layer protects against this only if someone deliberately designs the new data model.
The pattern does not fit when requests to the old system cannot be intercepted, when there is access neither to the old system's code nor to its database, when the system is small and easier to replace in full, or when the old system has to be switched off quickly. The Microsoft Azure Architecture Center guide lists the same cases.
Examples
The strangler fig pattern was used to replace an ESB with an event platform for payments. A similar incremental route is described in the migration of an online store to headless architecture: the new front end takes over page types one by one, and the commerce back end is replaced last. The same approach works for IBM i modernization, where old code stays until new modules take over its work.
We prepare the system map, module boundaries and data plan in our Analysis and architecture service, before the team moves the first function. How to work out what costs the most in an old system is covered in Technical debt.
Questions and answers
How long does a strangler fig modernization take?
It depends on the size of the system and the number of domains. The first module with the facade and data sync usually takes a few months, because that is when all the transitional infrastructure gets built. Later ones go faster. The plan should include a date for switching off the old system, otherwise the migration drags on forever.
Can you keep developing the old system during the migration?
You can, but every change to a function that is being migrated means double work. A good rule: new features are built in the new system, and the old one gets only bug fixes and changes required by law.
Does strangler fig require microservices?
No. The new system can be microservices, but it can just as well be a modular monolith with clear module boundaries. The pattern is about how you get there, not about the target architecture. The options are compared in Modular monolith.
What about reports that read the entire old database?
Reports move to a data warehouse or a reporting database fed from both systems. While a domain lives in two databases, the report has to know which one is the source of truth. Without that, report figures will drift during the migration.