liveBook · Manning

Strangler fig pattern

As explained in Grokking Software Architecture

A gradual modernization technique that replaces a legacy system by moving functionality into a new system until the old system is no longer needed.

A strangler fig grows around a host tree until the original tree is no longer needed. The strangler pattern applies the same idea to software: build a replacement around a legacy system, move functionality into it gradually, and retire the old system when it is no longer needed. section 5.7 section 12.5.1

The alternative is a big-bang rewrite: stop delivering features while the team rebuilds everything. A gradual migration lets the business keep moving while individual pieces are replaced. It is not free, though: new boundaries add complexity, and splitting a monolith across a network affects speed and reliability. section 12.5 section 5.7.1 section 12.5.2

One way to start is with a hexagonal outpost:

  • Find a seam: choose an isolatable feature or bug-fix area. section 5.7.1
  • Build the new logic in a separate hexagonal boundary, defining a port for what it needs. section 5.7 section 5.7.1
  • Create an adapter that satisfies the port by calling the legacy code or database. section 5.7.1
  • Move more logic into the new boundary over time, until the old host is no longer needed. section 5.7.1

Strangling a shop monolith

A team moves billing into a new service and configures an API gateway to send /billing requests there. The old billing code stops receiving that traffic. The team repeats the move for inventory and shipping; once all routes point to replacements, the legacy server can be shut down. Moving data is a major challenge: change data capture can stream database transaction logs from the old system to the new one. section 12.5.2 section 12.11

Figure 12.4 The Strangler Fig Migration. Instead of a risky "Big Bang" rewrite, an API Gateway incrementally reroutes traffic to the new Microservice, while Change Data Capture (CDC) safely syncs the underlying data in the background.

The diagram brings the traffic shift and background data synchronization together in one migration picture. section 12.5.2

Choose a small, isolatable starting point and count the cost of the new boundaries before expanding. Gradual replacement avoids a single disruptive cutover, but it does not make the complexity of migration or distributed services disappear. section 5.7.1 section 12.5.2

How Grokking Software Architecture covers it

How deep it goes
Outlines hexagonal migration steps and a service-routing example, while deferring detailed implementation of the refactor.
Examples
Illustrates legacy replacement with a hexagonal outpost and a shop monolith whose billing, inventory, and shipping routes move to services.
What you can do after
Practice/perform a basic migration plan by identifying a seam, creating a legacy adapter, and shifting logic incrementally.
How it connects
Connects hexagonal architecture, ports and adapters with API gateways, microservices, and change data capture.

Also explained in

Compare how 6 books explain strangler fig pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.