
Strangler Fig: how to migrate from a monolith to microservices
Almost all of us developers have been there at some point: you arrive at a new project or company with all the motivation in the world, you open the repository, and you find a giant monolith, written eight or ten years ago, where no one dares to touch certain classes for fear that billing or user login will go down.
In that moment, the first idea that usually crosses our minds tends to be radical: "this is useless, we have to rebuild everything from scratch with modern technologies." The truth is that dreaming of a completely new application from a blank sheet is tempting, but when you sit down with the product team and the business, reality hits head-on: you can't freeze the company for an entire year to rewrite code while the competition keeps shipping features.
Does that mean we have to live forever with technical debt? Not at all. If you structure it well, you can build it step by step, and the best architectural tool to achieve this without stopping operations is the Strangler Fig pattern.
What is the Strangler Fig pattern and why does it help us so much?
The name of this pattern comes from a botanical metaphor observed by Martin Fowler: there are certain fig trees called strangler figs whose seeds germinate high up in the branches of a host tree. Over time, they send roots downward until they surround the original trunk, absorb its resources, and finally replace it completely.
Applied to our day-to-day work in software architecture, this pattern proposes the following idea: instead of replacing an entire system all at once, we gradually extract small functionalities into independent services and redirect traffic little by little, until the original monolith is empty and we can shut it down safely.

This cycle is divided into three iterative phases:
- Transform: We design and build a specific functionality in a new service with clean code, automated tests, and good practices.
- Coexist: We put the old monolith and the new service to coexist in production. An intermediary (such as a reverse proxy or an API Gateway) is responsible for directing each request to the right place.
- Eliminate: Once we confirm that the new service processes traffic stably and without errors, we delete the corresponding old code inside the monolith. Less legacy code, fewer headaches.
Steps for an incremental migration
When we decide to apply this pattern in a real project, it is crucial to have patience and method. If you try to extract the most tangled part of your application in the first week, you will get frustrated very quickly.
1. Choose an isolated functionality (Bounded Context)
The most common mistake when starting is trying to migrate the core of the business all at once. The most advisable thing is to look for a small domain with few dependencies on other tables or classes.
- Ideal functionalities to start with: the email or notification sending module, the generation of analytical PDF reports, or a frequently read catalog.
- If something fails in this first extraction, the impact on the customer's operation will be minimal, and you will have time to fix it without panicking.
2. Place a facade or interception layer
Before creating the first microservice or touching a single line of the monolith, place an intermediate entry point in front of your application. Tools such as NGINX, HAProxy, or an API Gateway work wonderfully here.
For clients (your React frontend, your mobile app, or external clients), the URL remains exactly the same. The difference is that now you have control over the routes at the network infrastructure level.
3. Build the new service and guarantee synchronization
This is where you apply your best technical skills: you create the microservice in the language that best suits the case (Java, Go, Node.js) with its own database. The key here is to ensure that the data does not get out of sync if the monolith still needs to query that information.
4. Divert traffic gradually
Don't switch 100% of traffic on the first day. You can start by sending only 5% or 10% of requests through canary testing or by initially enabling it for internal test users. Once you see that latency, memory usage, and error logs remain stable, you redirect all traffic to that route.
Technical implementation: Configuration with NGINX
Let's look at a specific case. Imagine you have an e-commerce monolith running at an internal address (10.0.1.20:8080) and you decided to extract the payments module into an independent microservice at (10.0.2.50:3000).
We configure NGINX as a facade to intercept only the payments route /api/v1/payments, keeping all other requests on the monolith:
Nginx
# Original monolith that continues handling most requests
upstream legacy_monolith {
server 10.0.1.20:8080 max_fails=3 fail_timeout=10s;
keepalive 32;
}
# The new payments microservice we just deployed
upstream payments_microservice {
server 10.0.2.50:3000 max_fails=3 fail_timeout=10s;
keepalive 32;
}
server {
listen 80;
server_name api.tuempresa.com;
# Standard headers to maintain request traceability
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# 1. We throttle the payments route: it is sent to the new microservice
location /api/v1/payments {
proxy_pass http://payments_microservice;
# Short timeouts to avoid leaving requests hanging
proxy_connect_timeout 5s;
proxy_read_timeout 15s;
proxy_send_timeout 15s;
}
# 2. Everything else continues to reach the monolith transparently
location / {
proxy_pass http://legacy_monolith;
proxy_connect_timeout 10s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
}
}
What do we achieve with this configuration?
- Zero changes on the client: The frontend team does not have to rewrite calls or update URLs in their code.
- Immediate reversibility: If the new payments service fails under real load, reverting the change is as simple as changing one line in NGINX and reloading the configuration (nginx -s reload). In less than a second the monolith takes back control without the need for an emergency deployment.
The hardest challenge: What is done with the database?
The truth is that separating the code is usually not the most complex part; the real challenge that becomes most difficult is the database. If the new service remains directly connected to the same tables as the monolith, the real coupling is not resolved.
To address this problem in an orderly way, there are two very useful strategies:
1. Change Data Capture (CDC)
Instead of forcing cross-queries between different databases, we listen to the changes that occur at the record level in the monolith's database (using tools such as Debezium with Apache Kafka). When the monolith updates a record, that event travels asynchronously to the microservice's database to keep it synchronized without blocking the application.
2. Anti-Corruption Layer (ACL)
Many times the old data model contains confusing column names or legacy logic that no longer makes sense. When creating the new service, do not contaminate your new design with those old structures; create an intermediate layer (ACL) that translates the monolith's responses into a clean, modern format adapted to your new domain.

Comparison of approaches: Full rewrite or Strangler Fig?
| Aspect to evaluate | Full rewrite (Big Bang) | Strangler Fig Pattern |
|---|---|---|
| Operational risk | Very high. An error on launch day stops the company. | Very low. Each change is deployed and tested in isolation. |
| Time to value delivery | Months or years until the user sees the first result. | Continuous, delivering improvements and value to production every few weeks. |
| Ease of rollback | Very difficult and costly in time and money. | Immediate, controlled with network rules on the reverse proxy. |
| Initial complexity | Apparently low at the start, but chaotic when integrating at the end. | Moderate from day one, as it requires synchronization and observability. |
Conclusion
Replacing a large, complex system doesn't have to become a painful project or a blind bet. When you break down a huge problem into small, manageable, and measurable steps, any application can be modernized successfully.
The Strangler Fig pattern gives us exactly that peace of mind: it allows us to innovate, test new technologies, and clean up the technical debt of an application while the business keeps billing and operating normally every day.
Previous Posts

PySpark vs Spark SQL vs Scala: differences and performance
PySpark, Spark SQL, or Scala? Compare their differences, performance, and use cases with a real lab of more than 3 million records.

Data Lake or Data Warehouse? Which to Choose and the Differences
Data Lake or Data Warehouse? Learn about their architectural differences, costs, real-world use cases, and how the Lakehouse unites the best of both worlds.
