A large working system can rarely be rewritten in one go: while the new one is being built, the old one still has to be maintained and extended. The strangler fig pattern offers the opposite path — grow the new system around the old one in small steps, without stopping operations.
How it works
- A facade is placed between the clients and the old system — a proxy, a gateway or a reverse proxy — which receives requests and decides where to route them.
- One function is migrated to the new system: it is rewritten alongside the old one, and the facade starts sending its requests to the new code.
- Step by step, the next function is migrated; the old system keeps running and serving whatever has not been migrated yet.
- When nothing is left to migrate and no client depends on the old system, the old system is switched off and the facade is removed.
Clients notice nothing: they keep using the same address, while the facade decides which system answers. For example, when moving an online shop off a monolith, the facade routes requests to GET /cart to the new cart service and the remaining paths to the monolith; over several iterations orders and payments move over the same way, and less and less of the old code remains.
When to use it
| A good fit | Not a good fit |
|---|---|
| A large system being replaced piece by piece to spread the risk and cost over time | The system is small, and replacing it in one go is simpler and cheaper |
| Client requests can be intercepted and redirected: a shared domain, a gateway, a load balancer | The old system cannot be reached: there is no access to its code and no point where requests can be intercepted |
| The old system must keep running without interruption while the migration is under way | The full replacement needs to be done quickly, not stretched over months and years |
The hardest part is the old system’s shared database: it is taken apart piece by piece as well, with tables and stored procedures moved into the databases of the new services and data kept in sync while both systems run together. When the new system needs to reach functionality that has not been migrated yet, or the other way round, a translation layer is placed between the systems to shield the new code from the old conventions.
Where the name comes from
Martin Fowler coined the term in his note “Strangler Application” of 29 June 2004: the strangler figs he had seen in 2001 in the rainforests of Queensland sprout on a host tree and eventually replace it. Later, Fowler added the word “fig” to the name to move away from the violent associations of the word “strangler”.
Sources
the term is written from these pagesVerified 8 Nov