Home/Learn/System Design/Strangler Fig Pattern

Strangler Fig Pattern

Advanced
Architectural Patterns

The Strangler Fig pattern incrementally migrates a monolith to microservices by gradually routing traffic from legacy endpoints to new services, eventually "strangling" the old system.

Overview

Named after strangler fig trees that grow around a host tree and eventually replace it, this pattern enables safe, incremental migration from a monolith to microservices. Instead of a risky big-bang rewrite, you place a facade (API gateway or proxy) in front of the monolith. New features are built as microservices. Existing features are migrated one at a time: the proxy routes specific endpoints to the new service while everything else still goes to the monolith. Over time, more and more routes are moved until the monolith can be decommissioned. The key advantage is reduced risk — the legacy system remains operational throughout the migration. Each migrated endpoint can be rolled back to the monolith if issues arise. This pattern works well with feature flags and canary deployments for gradual cutover.

Migration Strategy

Place a proxy/gateway in front of the monolith. Build new service. Route specific endpoints to new service. Verify. Repeat until monolith is empty.

Conceptual + NGINX — strangler fig migration
// Strangler Fig migration phases
//
// Phase 1: Proxy in front of monolith (everything goes to monolith)
// Client → API Gateway → Monolith (all endpoints)
//
// Phase 2: Extract UserService
// Client → API Gateway
//   /api/users/**  → NEW UserService (microservice)
//   /api/*         → Monolith (everything else)
//
// Phase 3: Extract OrderService
// Client → API Gateway
//   /api/users/**  → UserService
//   /api/orders/** → NEW OrderService
//   /api/*         → Monolith (shrinking)
//
// Phase N: Monolith is empty → decommission
// Client → API Gateway → All microservices

// NGINX routing during migration
upstream monolith { server monolith:8080; }
upstream user_service { server user-svc:8080; }
upstream order_service { server order-svc:8080; }

server {
    location /api/users/ { proxy_pass http://user_service; }
    location /api/orders/ { proxy_pass http://order_service; }
    location / { proxy_pass http://monolith; }  # default: monolith
}

Data Migration

The hardest part is splitting the shared database. Use change-data-capture (CDC) to sync data during the transition period. Eventually cut over to the new service's database.

Conceptual + JSON — database migration with CDC
// Database migration strategy
//
// Step 1: New service reads from monolith DB (shared, temporary)
// Step 2: New service gets its own DB
//         CDC (Debezium) syncs monolith DB → new service DB
// Step 3: New service reads/writes its own DB
//         Verify data consistency
// Step 4: Remove CDC sync, decommission monolith tables

// Debezium CDC — sync monolith → new service
{
  "name": "users-cdc",
  "config": {
    "connector.class": "io.debezium.connector.mysql.MySqlConnector",
    "database.hostname": "monolith-db",
    "database.include.list": "monolith",
    "table.include.list": "monolith.users,monolith.user_profiles",
    "topic.prefix": "migration"
  }
}
// Kafka topic: migration.monolith.users
// New UserService consumes → populates users_db

Key Points to Remember

  • 1Strangler Fig enables incremental monolith-to-microservices migration without big-bang rewrite.
  • 2A proxy/gateway routes traffic — new endpoints go to microservices, rest stays on monolith.
  • 3Each migrated endpoint can be rolled back to the monolith if issues arise.
  • 4Database splitting is the hardest part — use CDC (Debezium) for transition period sync.
  • 5Combined with feature flags and canary deployments for low-risk cutover.

Interview Questions

Sign in to ask Aria
1

What is the Strangler Fig pattern?

EasyTCS
2

How do you route traffic during a monolith-to-microservices migration?

MediumAmazon
3

What is the biggest challenge in strangler fig migration and how do you solve it?

MediumGoogle
4

How do you handle the shared database during migration?

HardFlipkart
5

Plan a strangler fig migration for a 500K-line monolith serving 10M users.

HardNetflix

Ask Aria about Strangler Fig Pattern

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…