Strangler Fig Pattern

Michael Morales  -  May 12, 2022  -  ,  

Any codebase that is old enough will ultimately contain legacy code. The moment architecture, performance, and comments are written, they begin to degrade.

Some parts of the codebase persist longer than others, but new coding standards will undoubtedly arise to eliminate technical debt. Then you have to redesign a major program with no downtime while creating a "new way" of working without compromising your release or development.

One successful solution is to use the Strangler Fig Pattern.

What does a Strangler Fig look like?

Strangler Fig Pattern derives from a group of plants that "strangle" their hosts as they grow. They thrive in scarce light, and they have evolved to disseminate their seeds (usually by birds) to the top of a host tree, where they may obtain plenty of it.

Their roots develop around the tree, while the seedlings grow upwards to absorb as much sunshine as possible. This "strangles" the tree, and the fig saplings often destroy the host tree on which they landed. What does this mean in terms of software?

What is the pattern of the Strangler Fig?

Rewriting a huge, complex codebase with many distinct interactions, typically involving multiple teams, is a planning nightmare. Going big-bang (releasing everything at once) on large, complicated brown-field projects like this forces you to:

  • Understand every interaction in detail to ensure you do not break anything when you release.
  • As you rewrite the codebase, include all new bug fixes in both codes.
  • keep both merged and up-to-date
  • spend weeks in testing 
  • dealing with numerous callouts, and providing after-hours help for the new codebase's implementation

To top it off, it usually results in a lot of overtime for developers and an onslaught of defects. When we use the Strangler Fig, one of the major challenges we aim to eliminate is making sure that anyone using your program knows where your new software is now available.

If you are rewriting your backend, for example, put everything on a new endpoint and ask your users to point to your new endpoint. However, if something goes wrong, you may have to ask everyone to return to the old one.

If you have tough bugs that are likely to frustrate your consumers, you may switch between these two destinations. We can avoid all of the above by using the Strangler Fig pattern.

Why are we suffocating our code?

The Strangler Fig pattern tries to rewrite small pieces of your codebase incrementally until you have strangled all of your previous codebases. It can be eliminated within a few months/years.

The general flow is as follows: add a new component to your system that has not been used yet, turn on the new part of the code (usually with a feature flag so it coexists with the old code), and remove the old code.

The Strangler Fig pattern's advantages

It not only helps you avoid all of the problems we have just described but it also:

  • reduces your risk when you need to update things
  • starts to give you benefits piece by piece
  • allows you to push your changes in small modular pieces that are easier to release
  • ensures zero downtime 
  • is generally more agile, 
  • makes rollbacks easier, 
  • allows you to spread your development on the codebase over a longer period if you have multiple priorities

The Strangler Fig pattern can be implemented in various ways, depending on the system you are deleting and so on. Let us get specific and look at an example.

Example: Façade Payment Provider

Assume you have a large monolithic back-end codebase for handling payments. It is enormous. You wish to rewrite a few million lines of code with various endpoints for various reasons into something fresh for your firm.

The design is too difficult for new developers to understand, and there is a lot of dead code you need to remove but do not want to break anything. Breaking a large codebase requiring client payments could result in the unfortunate developer pushing up last and losing their job!

How do you gradually eliminate this ancient codebase? This is challenging. You don't want to add a new endpoint and compel everyone to transfer simply. If you have faults and need to roll back, you can not merely switch back and forth.

You do not want to alter your interfaces to these endpoints to add one more hurdle. Everything that is supplied as an argument or returned should be identical.

Pattern-based Strangler Fig Solution

We can build a front end that intercepts requests for legacy endpoints. The new façade will redirect to the new API you created or the legacy API if you have not updated that part of the software.

This facade acts as a shim, catching network requests and routing them to the appropriate destination. You may then gradually migrate to the new API, with your users oblivious of any changes to your underlying code because you have properly abstracted it away.

If you complete it correctly, you should be able to:

  • Use the legacy method.
  • Create a new API.
  • Allow it to coexist with the legacy API and toggle it on and off using feature flags.
  • Move more and more across to the new API
  • When you have completed the migration, delete the old method.

The strangling happens in stages as you shift more and more responsibilities away from the legacy API and toward the new API.


I hope this has clarified the Strangler Fig Pattern and some of its advantages. This pattern has been utilized in real software projects and has proven quite effective. It was easily one of the most difficult tasks I have ever worked on, and the Strangler Fig made it a breeze.

It keeps you from spending months writing software projects and then crossing your fingers that you have not forgotten anything before putting it into production.

If you want to learn more about computer code and programming, here’s an article on why algorithms are important.

Main Image: Click here

What Is Computer Programming?
What Is Computer Programming?
A computer program is a collection of instructions, or code, that can be loaded into and run on a computer ...
What Is Coding In Computer Programming?
What Is Coding In Computer Programming?
Code is required for the proper operation of electronic gadgets such as cell phones, laptops, and tablets. Humans can communicate ...
How To Start Computer Programming?
How To Start Computer Programming?
There is never been a better moment to learn to code than now, thanks to the internet. Unfortunately, the sheer ...
1 2 3 31
J-sim's goal is to be one of the broadest online sources of content for Computer Technology, Internet Security, and anything within the World Wide Web. We aim to provide the information and tools needed to help enhance our readers' minds when it comes to today's technological advancements.
Copyright © 2022 j-sim. All Rights Reserved.
DMCA.com Protection Status