What is Strangler Fig Migration?
The strangler fig pattern is an incremental migration technique in which a routing façade sits in front of a legacy application, new features are built in the new stack, and existing features move across one at a time until nothing routes to the old system and it can be switched off. It replaces a big-bang rewrite with continuous, reversible delivery.
Big-bang rewrites fail often: they freeze features, delay value and concentrate every risk into a single cutover. The strangler fig pattern, named by Martin Fowler after the vines that grow around a host tree until they can stand alone, replaces a legacy system piece by piece behind a routing layer until the old system can be switched off. After PHP2Shell, that approach lets a business shrink its internet-facing PHP exposure immediately while migrating to TypeScript and Node.js safely. Five building blocks make it work: a routing façade, shared authentication, a data strategy, feature flags and characterization tests.
Why Not Just Rewrite?
When a legacy PHP application becomes painful, rebuilding it properly from scratch is the tempting answer, and industry experience suggests caution. A rewrite means a feature freeze while the business waits months or years for the new system to catch up, hidden rules that legacy code encodes as undocumented edge cases discovered only in production, one huge cutover where a single mistake affects every user, and a moving target because the old system keeps changing during the work. Joel Spolsky called rewriting from scratch the single worst strategic mistake a software company can make. That is an overstatement for every case, but it is a useful warning: the risk is concentrated, and the value arrives late.
What the Strangler Fig Pattern Is
Martin Fowler named the pattern after strangler figs, which grow around a host tree until they can stand on their own. In software you put a façade, such as a router or proxy, in front of the legacy application, build new functionality in the new stack and route specific paths or features to it, migrate existing features one at a time by switching routes as each one is ready, and when nothing routes to the legacy system any more, switch it off. Microsoft's Azure Architecture Center documents the same pattern for cloud modernisation. The diagram below shows the shape: users hit a routing façade, migrated paths reach the new TypeScript app, everything else still falls through to legacy PHP, and both share the data layer.
flowchart LR
U[Users] --> F[Routing facade CDN / reverse proxy / Next.js middleware]
F -->|migrated paths| N[New TypeScript app Next.js + Node.js]
F -->|everything else| L[Legacy PHP app]
N --> DB[(Data layer)]
L --> DBWhy It Fits the Post-PHP2Shell Moment
PHP2Shell let unauthenticated attackers execute code on any vulnerable PHP server, so organizations now face two pressures at once: reduce PHP exposure now, and do not break the business with a risky rewrite. The strangler fig serves both. On day one the façade can move public, unauthenticated routes — marketing pages, login, sign-up, public APIs — to the new stack and restrict the legacy PHP app to authenticated users, internal networks or specific IP ranges, which means less internet-facing PHP and less PHP2Shell-class risk. Each migrated module ships to production continuously, and if a migrated route misbehaves you can flip it back, because every step is reversible.
Warning
The legacy PHP app still needs patching throughout the migration — PHP 8.5.12, 8.4.27, 8.3.36 or 8.2.35. The strangler fig reduces exposure; it does not replace patching.
The Routing Façade
The façade is the single most important piece, and the options range from simplest to most flexible. CDN rules on Cloudflare, Fastly or CloudFront route by path at the edge; a reverse proxy such as Nginx, Traefik or Envoy can route by path, header or cookie; or the new Next.js app itself becomes the front door and proxies unmigrated paths to PHP with rewrites. The config below lets Next.js handle filesystem routes first and falls through everything else to the legacy app, which is enough to start moving routes on day one.
import type { NextConfig } from 'next'
const config: NextConfig = {
async rewrites() {
return {
fallback: [
{ source: '/:path*', destination: 'https://legacy-internal.example.com/:path*' },
],
}
},
}
export default configShared Auth, Data and Rollout
Users must not notice which system serves a page, so authentication is shared: a central identity provider such as Auth0, Cognito, Supabase Auth or Keycloak used by both systems, a session bridge where the new app validates the legacy PHP session through an internal endpoint or shared Redis store, or a signed JWT cookie issued by the new app and accepted by thin PHP middleware. On data, start by sharing the legacy MySQL database so there is no sync to worry about, then move ownership of each domain's tables to PostgreSQL as its module migrates, using change-data-capture or events to keep the legacy system informed and an anti-corruption layer so data quirks do not leak into the new model. Feature flags from LaunchDarkly, Unleash or GrowthBook route a percentage of users, internal staff or specific tenants to the new module, while characterization tests capture real legacy behaviour and shadow traffic compares responses without affecting users.
A Six-Phase Migration
The sequence matters as much as the pattern. Week zero is patch and protect: patch PHP, rotate secrets and put a CDN or WAF in front, which is non-negotiable. Weeks one to three stand up the routing façade, build the TypeScript foundation with Next.js, auth, roles, observability, CI/CD and infrastructure as code, and set up shared authentication. Weeks three to six move the public edge — public pages, marketing content, login and sign-up — into the new app and restrict direct internet access to the legacy app. Weeks six to ten take the first bounded business module through characterization tests, build, shadow testing and gradual rollout. From there you iterate domain by domain in risk-times-value order, moving table ownership to PostgreSQL, until the final phase routes all traffic to the new stack, archives legacy data, exports audit logs and switches off the PHP servers.
Choosing the First Module
A good first module is clearly bounded with few dependencies, delivers visible value so stakeholders see progress, carries moderate risk — not the payment engine on day one — is read-heavy so it is easier to verify with fewer data-consistency problems, and is painful in PHP today so the improvement is obvious. Reporting and dashboards, customer self-service portals and admin tools are classic first picks, and they also make good places to introduce AI features such as natural-language reporting or in-product assistants.
Handling the Hard Parts
Sessions must work across two systems, so use a central identity provider or session bridge on the same cookie domain. Shared database schema changes follow expand-and-contract migrations where the new app owns new columns. Background jobs move with their domain and use locks for exactly-once delivery. PHP-serialised data sitting in columns is decoded once into JSONB at the anti-corruption layer, and encoding mismatches such as latin1 versus UTF-8 are normalised at that boundary and fixed at the source during migration. URL and SEO continuity means keeping paths and issuing 301 redirects at the façade for anything that changes. Long-tail admin screens can be replaced with a Payload CMS admin or a generated admin, retiring the ones nobody uses, and the team should stay cross-functional with one group owning both sides of each migrated module.
Measuring Progress
Track six numbers on a simple dashboard: the percentage of requests served by the new stack, which is the headline metric; the percentage of internet-facing routes still on PHP, which is your PHP2Shell-class exposure; the number of PHP endpoints remaining; change failure rate and lead time for new versus legacy code using DORA metrics; incidents and error rates per module; and infrastructure cost for legacy versus new. When the first two numbers reach 100 percent and 0 percent respectively, the migration is finished and the legacy system can be retired.
How App Corp Runs Strangler Migrations
App Corp's senior engineers have delivered platform rebuilds and migrations, including a Rails-to-microservices migration described in client testimonials, and we run strangler-fig projects in fixed-scope phases so you always know what is being delivered and what it costs. The pre-built path uses our TypeScript foundation with Next.js, auth, RBAC, multi-tenancy, billing, Payload admin and CI/CD as the fig, with the routing façade stood up in week one and the public edge migrated first for an immediate drop in PHP exposure; it suits SaaS products, portals and B2B apps on Laravel, CodeIgniter or custom PHP. The custom path adds domain-driven decomposition, an architecture design phase, event-driven integration with change-data-capture into PostgreSQL, and compliance requirements such as HIPAA, PCI DSS and SOC 2; it suits large business-critical systems that cannot stop. Every phase ends in production value and moves you closer to switching PHP off for good.
Sources and references
Martin Fowler introduced the pattern in StranglerFigApplication at martinfowler.com/bliki. Microsoft Learn documents the Strangler Fig pattern at learn.microsoft.com/azure/architecture/patterns/strangler-fig and the Anti-corruption Layer pattern at learn.microsoft.com/azure/architecture/patterns/anti-corruption-layer. Joel Spolsky's Things You Should Never Do, Part I is at joelonsoftware.com. DORA metrics come from dora.dev. Wiz Research's PHP2Shell write-up is at wiz.io/blog/php2shell-php-rce, and Recorded Future's exploitation notes at recordedfuture.com. Next.js rewrite configuration is documented at nextjs.org/docs, and Payload CMS documentation at payloadcms.com/docs.
Common strangler-fig problems and their fixes
| Challenge | Solution |
|---|---|
| Sessions across two systems | Central identity provider or session bridge on the same cookie domain |
| Shared database schema changes | Expand-and-contract migrations; the new app owns new columns |
| Background jobs and cron | Migrate jobs with their domain; ensure exactly-once with locks |
| Serialized PHP data in columns | Decode once into JSONB in the anti-corruption layer |
| Encodings such as latin1 versus UTF-8 | Normalise at the anti-corruption layer boundary; fix at the source during migration |
| URL and SEO continuity | Keep paths; issue 301 redirects at the façade |
| Long-tail admin screens | Replace with a Payload CMS admin or a generated admin; retire unused ones |
| Team split between old and new | One cross-functional team owns both sides of each migrated module |
Almost every hard part of a strangler migration is solved at the façade or the anti-corruption layer, not inside the legacy app.
A six-phase strangler migration
- 1
Patch and protect
Week 0: patch PHP to 8.5.12, 8.4.27, 8.3.36 or 8.2.35, rotate secrets, and put a CDN or WAF in front of the legacy app.
- 2
Façade and foundation
Weeks 1 to 3: stand up the routing façade, build the TypeScript foundation with Next.js, auth, roles, observability and CI/CD, and share authentication.
- 3
Move the public edge
Weeks 3 to 6: migrate public pages, marketing content, login and sign-up to the new app and restrict direct internet access to legacy PHP.
- 4
Ship the first business module
Weeks 6 to 10: pick a bounded, valuable module such as reporting or invoicing, write characterization tests, shadow the traffic and roll out gradually.
- 5
Iterate module by module
Ongoing: repeat for each domain in risk-times-value order and move table ownership to PostgreSQL as each domain migrates.
- 6
Decommission PHP
Final: route 100 percent of traffic to the new stack, archive legacy data, export audit logs, then switch off and delete the PHP servers.
A legacy PHP estate that shrinks every phase while new features ship to production, ending with the PHP servers switched off and deleted.
Conclusion
You do not have to choose between a risky rewrite and years of patching legacy PHP. Grow the new TypeScript system route by route, retire the old PHP app when nothing points at it, and keep shipping features the whole way. App Corp runs strangler-fig migrations in fixed-scope phases: the façade goes up in week one, the public edge moves first to cut exposure, and every following module reaches production before the next begins. Patch PHP in parallel, because reducing exposure never replaces the fix.
Frequently Asked Questions
Key Takeaways
- Big-bang rewrites freeze features and concentrate risk in a single cutover
- The strangler fig pattern replaces a legacy system piece by piece behind a routing façade
- Moving public, unauthenticated routes first shrinks PHP2Shell exposure on day one
- Five building blocks carry the architecture: façade, shared auth, data strategy, feature flags and characterization tests
- The legacy PHP app still needs patching throughout, because reducing exposure never replaces the fix