Skip to content
AI360Xpert

Strangler Fig Pattern

Strangler Fig Pattern architecture
Strangler Fig Pattern architecture

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.

🧠 Mental model: The Strangler Fig is a tree that grows around an older, existing tree. Over time, the fig tree grows larger, taking over the sunlight and root space, until the old tree inside dies and rots away, leaving only the new tree standing.

Key Concepts

How it works

  1. Insert a Facade: Place an API Gateway or Reverse Proxy in front of the legacy monolith. Initially, 100% of traffic routes to the monolith.
  2. Build a Microservice: Extract one specific, cohesive feature (e.g., the User Profile service) and build it as a modern microservice.
  3. Reroute Traffic: Update the Facade so that calls to /api/users go to the new microservice, while all other traffic still goes to the monolith.
  4. Repeat: Continue extracting features one by one, shifting traffic piece by piece.
  5. 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.