image

Surviving Legacy Code Migrations with the Strangler Fig Pattern

18 Nov, 2026 Abdelrahman Etry

Rewriting a 10-year-old native PHP or CodeIgniter monolith from scratch is one of the highest-risk moves an engineering team can make. Feature freezes stall the business for months, undocumented edge cases get missed, and "big bang" cutover weekends routinely end in rollbacks.

The Strangler Fig Pattern eliminates cutover risk by letting your new Laravel application gradually wrap around and replace the legacy system route-by-route in production.


How the Architecture Works

Instead of replacing the application all at once, you place a reverse proxy (Nginx or Caddy) in front of both codebases:

  1. Default Fallback: By default, all HTTP traffic continues routing to the legacy PHP app untouched.

  2. Route-by-Route Takeover: When you rebuild a module—such as /invoices or /api/v2/orders—in Laravel, you add a specific location rule in Nginx forwarding only those paths to Laravel.

  3. Shared Authentication Bridge: Both applications read from the same Redis session store or verify a shared encrypted cookie/JWT, so users move seamlessly between legacy screens and modern Laravel pages without logging in twice.


# Nginx routing: migrated routes hit Laravel, everything else falls back to Legacy PHP
location ^~ /billing {
    try_files $uri $uri/ /laravel/public/index.php?$query_string;
}

location / {
    try_files $uri $uri/ /legacy/index.php?$query_string;
}


Handling Database Evolution Safely

During the transition, both codebases share the underlying database. Never rename or drop legacy columns while old code still reads them. Instead, use the Expand and Contract pattern: add new normalized columns or tables, sync writes via database triggers or Laravel model observers, and drop legacy columns only after the old route is decommissioned.