0
0
MicroservicesConceptBeginner · 3 min read

Strangler Fig Pattern: Microservices Migration Explained

The Strangler Fig Pattern is a software design approach that gradually replaces parts of a legacy system with new microservices. It works by slowly routing requests from the old system to new components until the legacy system is fully replaced.
⚙️

How It Works

Imagine a big old tree that is slowly surrounded and overtaken by a new, strong tree growing around it. The Strangler Fig Pattern works similarly for software. Instead of rewriting a whole legacy system at once, you build new features as separate microservices around it.

Over time, you redirect parts of the system’s traffic from the old code to the new microservices. This happens bit by bit, so the legacy system is 'strangled' and eventually replaced without stopping the whole system.

This approach reduces risk and downtime because you can test and deploy new parts independently while the old system still runs.

💻

Example

This simple example shows how a request router can gradually send traffic to a new microservice instead of the legacy system.

javascript
class LegacySystem {
    handleRequest() {
        return 'Response from legacy system';
    }
}

class NewMicroservice {
    handleRequest() {
        return 'Response from new microservice';
    }
}

class Router {
    constructor() {
        this.useNewService = false;
        this.legacy = new LegacySystem();
        this.newService = new NewMicroservice();
    }

    routeRequest() {
        if (this.useNewService) {
            return this.newService.handleRequest();
        } else {
            return this.legacy.handleRequest();
        }
    }

    switchToNewService() {
        this.useNewService = true;
    }
}

const router = new Router();
console.log(router.routeRequest()); // Response from legacy system
router.switchToNewService();
console.log(router.routeRequest()); // Response from new microservice
Output
Response from legacy system Response from new microservice
🎯

When to Use

Use the Strangler Fig Pattern when you want to modernize a large legacy system without stopping it. It is ideal for:

  • Gradual migration to microservices
  • Reducing risk by deploying small parts independently
  • Improving system maintainability step-by-step
  • Handling complex systems where full rewrite is too risky or costly

Real-world cases include moving a monolithic web app to microservices or replacing old APIs with new ones without downtime.

Key Points

  • The pattern replaces legacy systems gradually, not all at once.
  • It routes requests between old and new components during migration.
  • Reduces risk and downtime by incremental changes.
  • Works well for large, complex systems needing modernization.

Key Takeaways

Strangler Fig Pattern replaces legacy systems gradually by routing requests to new microservices.
It reduces risk by allowing incremental migration without full system downtime.
Ideal for modernizing large, complex systems step-by-step.
Helps maintain system stability while improving architecture.
Routing logic controls which system handles each request during transition.