Strangler Fig Pattern
Overview
The Strangler Fig pattern is a migration strategy for incrementally replacing a legacy system (usually a monolith) with a new system (usually microservices). Instead of rewriting everything from scratch in a risky "big bang" release, you build a facade that intercepts calls to the legacy system and slowly route specific endpoints to the new microservices.
Key Concepts
How it works
- Insert a Facade: Place an API Gateway or Reverse Proxy in front of the legacy monolith. Initially, 100% of traffic routes to the monolith.
- Build a Microservice: Extract one specific, cohesive feature (e.g., the User Profile service) and build it as a modern microservice.
- Reroute Traffic: Update the Facade so that calls to
/api/usersgo to the new microservice, while all other traffic still goes to the monolith. - Repeat: Continue extracting features one by one, shifting traffic piece by piece.
- Strangle: Once all features are extracted, the monolith receives no traffic and can be safely deleted.
Trade-offs
This pattern vastly reduces the risk of migrations because you can easily roll back a single endpoint if a new microservice fails. It also delivers value continuously rather than waiting years for a rewrite. However, managing data synchronization is the hardest part. While the migration is ongoing, both the monolith and the new microservices might need access to the same data, requiring complex dual-writes or database-level replication that can lead to data inconsistency.
Interview Tips
- If an interviewer asks "How would you migrate this old monolithic system to microservices?", Strangler Fig is the exact industry-standard answer they want to hear.
- Explicitly say you would never attempt a "Big Bang Rewrite."
- Acknowledge that data migration (the database) is the hardest part of the Strangler pattern, and suggest extracting "edge" services first that have fewer database dependencies.
Summary
- The Strangler Fig pattern incrementally replaces a legacy monolith with microservices.
- It uses an API Gateway to route specific traffic to new services while keeping the rest on the monolith.
- It avoids the massive risk of a 'Big Bang' rewrite.
- Value is delivered continuously as individual services are extracted.
- Data synchronization between the old and new systems during the transition is the biggest challenge.