← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Strangler Fig Pattern

quality PHP 5.0+ Intermediate

Also Known As

strangler fig pattern strangler pattern incremental migration

TL;DR

Incrementally replace a legacy system by routing new requests to a new implementation while the old system handles the rest.

Explanation

The Strangler Fig pattern (Martin Fowler, named after the plant that slowly replaces its host tree) migrates a legacy system by building new functionality alongside it and gradually routing traffic to the new system. A routing layer (facade) intercepts requests and directs them to old or new code based on what's been migrated. Over time, the legacy system shrinks as the new one grows, until the old system can be safely decommissioned. This avoids the risk and disruption of a big-bang rewrite.

Diagram

flowchart TD
    subgraph Phase 1 - Intercept
        C1[Client] --> PROXY[Proxy / Facade]
        PROXY -->|all requests| LEGACY[Legacy Monolith]
    end
    subgraph Phase 2 - Migrate
        C2[Client] --> PROXY2[Proxy]
        PROXY2 -->|/users| NEW[New User Service]
        PROXY2 -->|everything else| LEGACY2[Legacy Monolith]
    end
    subgraph Phase 3 - Complete
        C3[Client] --> PROXY3[Proxy]
        PROXY3 --> NEW2[New Services]
        LEGACY3[Legacy<br/>decommissioned]
    end
style NEW fill:#238636,color:#fff
style LEGACY fill:#f85149,color:#fff
style NEW2 fill:#238636,color:#fff
style LEGACY3 fill:#d29922,color:#fff

Common Misconception

The strangler fig pattern requires a big-bang cutover at the end. The pattern specifically avoids big-bang cutovers — traffic is gradually shifted to the new system route by route until the legacy system handles nothing and can be deleted.

Why It Matters

The Strangler Fig pattern replaces a legacy system incrementally by routing new traffic to new code while old code handles what hasn't been migrated — zero big-bang rewrites, continuous delivery throughout.

Common Mistakes

  • Not defining a proxy/facade layer to route between old and new — migrations happen directly in the old codebase.
  • Migrating too many components simultaneously — the pattern works because it is incremental.
  • Not deleting old code after migration — the legacy system remains and accumulates debt alongside the new.
  • Applying the pattern to entirely greenfield development — it is a migration strategy, not an architecture.

Avoid When

  • The legacy system is too tightly coupled to allow incremental routing — full rewrite may be unavoidable.
  • The team lacks the discipline to maintain both systems — the old system rarely gets retired in practice.
  • Short-lived projects where the migration will outlast the business need.
  • Systems where traffic cannot be routed at the boundary — embedded or monolithic deployments with no HTTP layer.

When To Use

  • Large legacy rewrites where replacing everything at once carries too much risk.
  • Systems that must remain live during migration — zero-downtime replacement.
  • When individual bounded contexts or features can be extracted and rerouted incrementally.
  • Teams that want to validate the new system on real traffic before full cutover.

Code Examples

💡 Note
The strangler fig grows around the old tree until the old tree is gone — applied to software, new code wraps old code and gradually replaces it.
✗ Vulnerable
// Big-bang rewrite instead of incremental strangling:
// Day 1: Stop all development on legacy app
// Week 12: Rewrite complete (it never is)
// Week 16: Still debugging, users still on legacy
// Strangler fig: route /new-feature to new app, /legacy-feature to old — migrate gradually
✓ Fixed
// Gradually replace legacy by routing traffic to new implementation
class OrderController {
    public function store(Request \$req): Response {
        if (\$this->flags->isEnabled('new_order_service')) {
            return \$this->newOrderService->place(\$req->validated());
        }
        return \$this->legacyOrderProcessor->process(\$req->all());
    }
}

// Increase rollout: 5% → 25% → 50% → 100%
// At 100% and stable, delete the legacy path

Added 15 Mar 2026
Edited 25 Mar 2026
Views 27
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
No pings yesterday
Amazonbot 9 Perplexity 7 Google 3 Ahrefs 2 ChatGPT 2 SEMrush 1
crawler 21 crawler_json 3
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: High
⚡ Quick Fix
Route a portion of traffic to the new implementation behind a feature flag; gradually shift traffic as confidence grows; decommission the old code when at 100%
📦 Applies To
PHP 5.0+ web api
🔗 Prerequisites
🔍 Detection Hints
Legacy monolith needing incremental replacement without big-bang rewrite
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update

✓ schema.org compliant