Bookmarks

Strangler fig pattern

An approach to replacing an old system with a new one without interrupting operation: new functionality is built up piece by piece around the old system, and once everything has been migrated, the old system is switched off.

Also: strangler fig application, strangler fig, strangler fig pattern, strangler application

checked 8 Nov

All terms

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

  1. 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.
  2. 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.
  3. Step by step, the next function is migrated; the old system keeps running and serving whatever has not been migrated yet.
  4. 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 fitNot a good fit
A large system being replaced piece by piece to spread the risk and cost over timeThe 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 balancerThe 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 wayThe 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 pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • API gateway

    An API gateway is a permanent part of the architecture, while the facade in strangler fig is a temporary layer that is removed once the replacement is complete.

  • monolith

    A monolith is a way of structuring a system, while strangler fig is a plan for replacing it gradually; both a monolith and a set of services can be replaced piece by piece.

In depth in the references

where the topic is covered in detail