Strangler Fig Pattern
A migration strategy that gradually replaces a legacy system by building new functionality alongside it until the old system can be decommissioned.
Also known as: Strangler Pattern, Strangler Application, Branch by Abstraction
Category: Software Development
Tags: software-engineering, architecture, migration, design-patterns, legacy-systems
Explanation
The Strangler Fig Pattern is a software migration strategy named after the strangler fig tree, which grows around a host tree, gradually replacing it. Similarly, this pattern replaces a legacy system incrementally by building new functionality alongside the old system.
## How it works
1. **Identify** - Choose a piece of functionality in the legacy system to replace
2. **Build** - Create the new implementation alongside the existing one
3. **Redirect** - Route traffic or calls from the old implementation to the new one
4. **Remove** - Once the new implementation is proven, remove the old code
5. **Repeat** - Continue with the next piece of functionality
## The facade/proxy layer
A key element is an intermediary layer (proxy, API gateway, or facade) that sits between consumers and the system. This layer controls routing:
- Initially, all requests go to the legacy system
- As new components are built, the proxy routes specific requests to them
- Eventually, all requests go to the new system
- The legacy system is decommissioned
## Why not rewrite from scratch?
Big-bang rewrites are notoriously risky:
- You must understand the entire system before replacing it
- No value is delivered until the rewrite is complete
- The legacy system is a moving target (it keeps changing)
- Hidden behaviors and edge cases are easy to miss
- Business can't wait for a multi-year rewrite
The strangler fig pattern mitigates these risks by delivering incremental value and reducing the blast radius of each change.
## When to use it
- Migrating from a monolith to microservices
- Replacing a legacy system with a modern one
- Migrating between technology stacks
- Gradually retiring technical debt
## Advantages
- **Low risk** - Small, reversible changes
- **Continuous delivery** - New functionality ships incrementally
- **Coexistence** - Old and new systems work together during transition
- **Learning** - Team gains understanding of the legacy system as they migrate it
## Challenges
- The proxy layer adds complexity
- Data consistency between old and new systems can be tricky
- Some systems are too tightly coupled to migrate incrementally
- Requires discipline to avoid maintaining both systems indefinitely
The pattern was named by Martin Fowler in 2004.
Related Concepts
← Back to all concepts