The Strangler Fig Pattern: Gradually Refactoring Monoliths into Microservices
Learn how to safely decompose a monolithic application into microservices, one piece at a time, without a risky "big bang" rewrite.
The Strangler Fig Pattern 🌳 helps you safely refactor a monolithic application by gradually replacing old functionality with new microservices, routing traffic through a facade.
🎯 System Scenario & Requirements
System Goal
The Strangler Fig Pattern 🌳 helps you safely refactor a monolithic application by gradually replacing old functionality with new microservices, routing traffic through a facade.
Actors & Components
- Legacy System
- New Microservices
- Client
- Strangler Facade
- Legacy Monolith
- New Service A (e.g., Orders)
- New Service B (e.g., Inventory)
Functional Requirements
- The Strangler Fig Pattern 🌳 helps you safely refactor a monolithic application by gradually replacing old functionality with new microservices, routing traffic through a facade.
- This reduces the risk of a "big bang" rewrite, allowing for continuous delivery and evolving bounded contexts.
- You're likely familiar with the challenge: an aging, tightly coupled monolithic application that has become a bottleneck for new feature development, scalability, and independent team work.
Constraints & Assumptions
- Operational latency, consistency levels, and network partition boundaries must be enforced.
⚡ Execution Stages & Decision Trace
Stage 1 — Growing New Contexts with the Strangler Fig
The Strangler Fig Pattern, inspired by the growth of a strangler fig tree around a host tree, provides a solution.
Instead of rewriting everything at once, you introduce a new facade (often an API Gateway or a reverse proxy) in front of the existing monolith.
Deep Dive
Deep Dive: Stage 1 — Growing New Contexts with the Strangler Fig
The Strangler Fig Pattern, inspired by the growth of a strangler fig tree around a host tree, provides a solution. Instead of rewriting everything at once, you introduce a new facade (often an API Gateway or a reverse proxy) in front of the existing monolith. As you identify new features or areas suitable for extraction into their own microservices (i.e., new bounded contexts), you build these new services independently. The facade then intelligently routes requests: new functionality goes to the new microservices, while existing, un-refactored functionality continues to be served by the old monolith. Over time, more and more functionality is "strangled" out of the monolith and replaced by new services, until eventually, the monolith itself can be retired. This allows teams to iterate, learn, and evolve their domain boundaries safely.
Observable outcome: This allows teams to iterate, learn, and evolve their domain boundaries safely.
Deep Dive: Stage 2 — Visualizing the Gradual Transition
Observable outcome: You can explain how “Visualizing the Gradual Transition” changes the architecture or implementation path.
Deep Dive: Stage 3 — Benefits and Considerations
The Strangler Fig Pattern offers significant advantages: reduced risk, continuous delivery, and the ability to learn and adapt your microservice boundaries over time. It allows you to tackle complexity in smaller, manageable chunks. However, it introduces an overhead of maintaining both the old and new systems concurrently, and the Strangler Facade itself can become a point of complexity if not managed well. Careful planning of domain boundaries (bounded contexts) and robust routing logic are key to a successful transition.
Observable outcome: Careful planning of domain boundaries (bounded contexts) and robust routing logic are key to a successful transition.
📊 System Outcome & Trade-offs
Observed User & Operator Behavior
User: Clients observe deterministic state without lost updates or race conditions.
Operator: Operators can verify stage outcomes against the scenario requirements.
Key Architectural Trade-offs
- System guarantees are traded against replication overhead and failover convergence times.
Key learnings
- The Strangler Fig Pattern, inspired by the growth of a strangler fig tree around a host tree, provides a solution.
- Apply design-patterns-gof to Visualizing the Gradual Transition.
- The Strangler Fig Pattern offers significant advantages: reduced risk, continuous delivery, and the ability to learn and adapt your microservice boundaries over time.
Apply Concepts from this Scenario
Test your understanding of the architecture decisions and trade-offs presented in this case study.
