Design Patterns

Strangler Fig

Understanding the strangler fig pattern for incremental migration.

3 min readConcepts · System Design

What is Strangler Fig?

The Strangler Fig pattern incrementally replaces a legacy system by gradually routing traffic to new components until the old system can be decommissioned. Named after strangler fig trees that grow around host trees.


The Pattern

Phase 1: New component alongside legacy

The PatternFlowchart

Phase 2: Gradual migration

The PatternFlowchart

Phase 3: Complete migration

The PatternFlowchart

How It Works

  1. Identify: Find functionality to migrate
  2. Build: Create new implementation
  3. Route: Proxy routes traffic based on rules
  4. Migrate: Gradually increase new system traffic
  5. Remove: Decommission legacy when complete

Implementation Strategies

By Feature

Migrate feature by feature:

/users/*     → New service
/orders/*    → Legacy (next)
/products/*  → Legacy

By User Segment

Route specific users to new system:

Beta users    → New system
Regular users → Legacy

By Percentage

Gradual rollout:

5% traffic  → New system (test)
50% traffic → New system (validate)
100% traffic → New system (complete)

Proxy/Router Patterns

URL-Based Routing

location /api/v2/users {
    proxy_pass http://new-service;
}

location /api/users {
    proxy_pass http://legacy;
}

Header-Based Routing

X-Use-New-System: true → New system
(no header)           → Legacy

Benefits

BenefitDescription
Reduced riskIncremental, rollback possible
Continuous deliveryDeploy without big bang
Learn and adaptAdjust based on feedback
Team productivityWork on new while legacy runs

Challenges

ChallengeMitigation
Data synchronizationShared database or sync mechanism
Feature parityPrioritize critical features
Testing both systemsComprehensive test coverage
Extended timelinePlan milestones, track progress

Data Migration

Options for handling data during migration:

Option 1: Shared Database

Data MigrationFlowchart

Option 2: Data Sync

Data MigrationFlowchart

Option 3: Event-Based

Data MigrationFlowchart

Real-World Example

E-commerce migration:

Week 1-4:   Product catalog → New system
Week 5-8:   User profiles → New system
Week 9-12:  Shopping cart → New system
Week 13-16: Checkout → New system
Week 17+:   Decommission legacy

Interview Tips

  • Explain incremental migration concept
  • Discuss routing strategies (URL, header, percentage)
  • Mention data synchronization challenges
  • Compare with big bang rewrite risks
  • Give use cases: monolith to microservices migration

Finished reading?

Mark it done to track your progress in Concepts.