Strangler Fig: Replace an Old System One Piece at a Time
When an old system is too tangled to keep fixing and too important to switch off for a rewrite, put a facade in front of it and move one feature at a time behind that facade to new code, with an adapter at the border so the old system's ideas don't leak in, until the old system has nothing left to do.
Freelancer · Software Development · OOP · Updated
After this lesson you can
- Replace an old system one feature at a time behind a facade, with an adapter at the border
- Spot the smells that point to Strangler Fig: a system too tangled to fix in place and too important to stop
Key takeaways
- The smell: a system too tangled to keep fixing in place, and too important to stop while it's rewritten.
- A big rewrite all at once is a long, risky bet: nothing ships until everything does, and the old system keeps changing underneath it.
- The fix: one front (a facade) that every caller uses, and behind it one feature at a time moved from the old system to new code, until the old one can be switched off.
- An adapter at the border translates the old system's data into the new code's shapes, so old ideas don't leak into new code.
Before this: Facade: One Button, Many Parts and Adapter: The Interpreter Between Two Strangers, the two patterns this one is built from, and Pin It Down.
Pinning and small steps have made Summit Gym's billing code safe to change. The rest of the system is another story. Its bookings, waitlists and reminders are tangled through GymManager and the old database, every fix breaks something two screens away, and the owner has decided: the gym needs a new booking system. The catch is that the gym takes bookings every hour of every day. It can't stop for the six months a rewrite would take. By the end of this lesson you'll have met the pattern teams use for exactly this, named after a tree: the strangler fig.
The problem story: too tangled to fix, too important to stop
The old system stores everything as text rows, like MAYA|BASIC, and three callers use it directly: the member app, the front desk and the website. Each one builds the old row format itself.
- The symptom: every change to the old system takes longer than the last, and fixing one feature breaks another. You've read its smells in the last chapter: all five families, at once.
- The cause: the old system's shape is spread through everything that uses it. There's no single border between "the old system" and "everything else".
- The cure: coming up, once we've tried the obvious fixes.
What would you try?
Keep fixing it in place. Pins and small steps work, one function at a time. But the tangle is the whole system, and the gym wants features the old database can't hold.
Rewrite it all, then switch over on one big day. It's the most tempting answer, and the riskiest. Nothing new reaches a member until everything is finished, the old system keeps changing while you rewrite it (so the target moves), and the switch-over day is one enormous change with no way to undo part of it.
Build the new system beside the old one and let each caller choose. Now the member app, the front desk and the website each need to know which system has which feature, and that knowledge moves every month. It's the tangle again, spread wider.
What a good fix needs: callers that don't know or care which system answers them, a way to move one feature at a time, and a border that keeps the old system's text rows out of the new code.
The everyday version
A strangler fig starts as a seed high up in an old tree. It sends roots down around the trunk, and over many years it grows its own trunk around the old one. The forest never sees a gap: there's a tree there the whole time. One day the old tree is gone, and the fig is standing on its own.

The fix: one front, one feature at a time
Put one front in front of the old system, and move one feature at a time behind it to new code, until the old system has nothing left to do. Every caller talks to the front, a facade, so callers never change while features move. Behind it, bookings move first, then waitlists, then reminders. When the last one has moved, the old system is switched off.

Step one changes nothing a caller can see: the front only passes each call to the old system. Every caller is moved to use the front, and the old row format now lives in one place:
GymFront front = new GymFront(new OldGym());
Console.WriteLine(front.Book("Maya", "Yoga"));
Console.WriteLine(front.Waitlist("Sam", "Spin"));
Console.WriteLine(front.Remind("Leo", "HIIT"));
// The old system: everything is a text row.
class OldGym
{
public string Book(string row) => quot;old system: booked {row}";
public string Waitlist(string row) => quot;old system: waitlisted {row}";
public string Remind(string row) => quot;old system: reminder for {row}";
}
// The front every caller uses. Today it passes everything to the old system.
class GymFront
{
private readonly OldGym old;
public GymFront(OldGym old) => this.old = old;
public string Book(string member, string kind) => old.Book(Row(member, kind));
public string Waitlist(string member, string kind) => old.Waitlist(Row(member, kind));
public string Remind(string member, string kind) => old.Remind(Row(member, kind));
private static string Row(string member, string kind) => quot;{member.ToUpper()}|{kind.ToUpper()}";
}
old system: booked MAYA|YOGA
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
// The old system: everything is a text row.
class OldGym {
String book(String row) { return "old system: booked " + row; }
String waitlist(String row) { return "old system: waitlisted " + row; }
String remind(String row) { return "old system: reminder for " + row; }
}
// The front every caller uses. Today it passes everything to the old system.
class GymFront {
private final OldGym old;
GymFront(OldGym old) { this.old = old; }
String book(String member, String kind) { return old.book(row(member, kind)); }
String waitlist(String member, String kind) { return old.waitlist(row(member, kind)); }
String remind(String member, String kind) { return old.remind(row(member, kind)); }
private String row(String member, String kind) { return member.toUpperCase() + "|" + kind.toUpperCase(); }
}
void main() {
GymFront front = new GymFront(new OldGym());
IO.println(front.book("Maya", "Yoga"));
IO.println(front.waitlist("Sam", "Spin"));
IO.println(front.remind("Leo", "HIIT"));
}
old system: booked MAYA|YOGA
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
class OldGym:
"""The old system: everything is a text row."""
def book(self, row):
return f"old system: booked {row}"
def waitlist(self, row):
return f"old system: waitlisted {row}"
def remind(self, row):
return f"old system: reminder for {row}"
class GymFront:
"""The front every caller uses. Today it passes everything to the old system."""
def __init__(self, old):
self.old = old
def book(self, member, kind):
return self.old.book(self._row(member, kind))
def waitlist(self, member, kind):
return self.old.waitlist(self._row(member, kind))
def remind(self, member, kind):
return self.old.remind(self._row(member, kind))
def _row(self, member, kind):
return f"{member.upper()}|{kind.upper()}"
front = GymFront(OldGym())
print(front.book("Maya", "Yoga"))
print(front.waitlist("Sam", "Spin"))
print(front.remind("Leo", "HIIT"))
old system: booked MAYA|YOGA
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
// The old system: everything is a text row.
class OldGym {
book(row) { return `old system: booked ${row}`; }
waitlist(row) { return `old system: waitlisted ${row}`; }
remind(row) { return `old system: reminder for ${row}`; }
}
// The front every caller uses. Today it passes everything to the old system.
class GymFront {
#old;
constructor(old) { this.#old = old; }
book(member, kind) { return this.#old.book(this.#row(member, kind)); }
waitlist(member, kind) { return this.#old.waitlist(this.#row(member, kind)); }
remind(member, kind) { return this.#old.remind(this.#row(member, kind)); }
#row(member, kind) { return `${member.toUpperCase()}|${kind.toUpperCase()}`; }
}
const front = new GymFront(new OldGym());
console.log(front.book("Maya", "Yoga"));
console.log(front.waitlist("Sam", "Spin"));
console.log(front.remind("Leo", "HIIT"));
old system: booked MAYA|YOGA
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
// The old system: everything is a text row.
class OldGym {
book(row: string): string { return `old system: booked ${row}`; }
waitlist(row: string): string { return `old system: waitlisted ${row}`; }
remind(row: string): string { return `old system: reminder for ${row}`; }
}
// The front every caller uses. Today it passes everything to the old system.
class GymFront {
private readonly old: OldGym;
constructor(old: OldGym) { this.old = old; }
book(member: string, kind: string): string { return this.old.book(this.row(member, kind)); }
waitlist(member: string, kind: string): string { return this.old.waitlist(this.row(member, kind)); }
remind(member: string, kind: string): string { return this.old.remind(this.row(member, kind)); }
private row(member: string, kind: string): string { return `${member.toUpperCase()}|${kind.toUpperCase()}`; }
}
const front = new GymFront(new OldGym());
console.log(front.book("Maya", "Yoga"));
console.log(front.waitlist("Sam", "Spin"));
console.log(front.remind("Leo", "HIIT"));
old system: booked MAYA|YOGA
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
Moving the first feature, with a border
Now bookings move. The new booking code needs to know each member's plan, and only the old system knows it, as a row like MAYA|BASIC. If the new code read those rows itself, the old format would leak into it, and the new system would carry the old one's ideas forever. So the new code asks an adapter at the border, which reads the old row and hands back a plain Member. That border has its own name: an anti-corruption layer, the layer that keeps the old system from corrupting the new one's design.
OldGym old = new OldGym();
GymFront front = new GymFront(old, new NewBookings(new OldMembers(old)));
Console.WriteLine(front.Book("Maya", "Yoga"));
Console.WriteLine(front.Waitlist("Sam", "Spin"));
Console.WriteLine(front.Remind("Leo", "HIIT"));
class OldGym
{
private readonly Dictionary<string, string> rows = new Dictionary<string, string> { ["MAYA"] = "MAYA|BASIC", ["SAM"] = "SAM|UNLIMITED" };
public string MemberRow(string name) => rows[name.ToUpper()];
public string Waitlist(string row) => quot;old system: waitlisted {row}";
public string Remind(string row) => quot;old system: reminder for {row}";
}
record Member(string Name, string Plan);
// The adapter at the border: old rows in, plain members out.
class OldMembers
{
private readonly OldGym old;
public OldMembers(OldGym old) => this.old = old;
public Member Find(string name) => new Member(name, old.MemberRow(name).Split('|')[1].ToLower());
}
// The new booking code never sees a row.
class NewBookings
{
private readonly OldMembers members;
public NewBookings(OldMembers members) => this.members = members;
public string Book(string name, string kind)
{
Member member = members.Find(name);
return quot;new system: {member.Name} ({member.Plan}) booked into {kind}";
}
}
class GymFront
{
private readonly OldGym old;
private readonly NewBookings bookings;
public GymFront(OldGym old, NewBookings bookings) { this.old = old; this.bookings = bookings; }
public string Book(string member, string kind) => bookings.Book(member, kind); // moved
public string Waitlist(string member, string kind) => old.Waitlist(Row(member, kind)); // not yet
public string Remind(string member, string kind) => old.Remind(Row(member, kind)); // not yet
private static string Row(string member, string kind) => quot;{member.ToUpper()}|{kind.ToUpper()}";
}
new system: Maya (basic) booked into Yoga
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
class OldGym {
private final Map<String, String> rows = Map.of("MAYA", "MAYA|BASIC", "SAM", "SAM|UNLIMITED");
String memberRow(String name) { return rows.get(name.toUpperCase()); }
String waitlist(String row) { return "old system: waitlisted " + row; }
String remind(String row) { return "old system: reminder for " + row; }
}
record Member(String name, String plan) {}
// The adapter at the border: old rows in, plain members out.
class OldMembers {
private final OldGym old;
OldMembers(OldGym old) { this.old = old; }
Member find(String name) { return new Member(name, old.memberRow(name).split("\\|")[1].toLowerCase()); }
}
// The new booking code never sees a row.
class NewBookings {
private final OldMembers members;
NewBookings(OldMembers members) { this.members = members; }
String book(String name, String kind) {
Member member = members.find(name);
return "new system: " + member.name() + " (" + member.plan() + ") booked into " + kind;
}
}
class GymFront {
private final OldGym old;
private final NewBookings bookings;
GymFront(OldGym old, NewBookings bookings) { this.old = old; this.bookings = bookings; }
String book(String member, String kind) { return bookings.book(member, kind); } // moved
String waitlist(String member, String kind) { return old.waitlist(row(member, kind)); } // not yet
String remind(String member, String kind) { return old.remind(row(member, kind)); } // not yet
private String row(String member, String kind) { return member.toUpperCase() + "|" + kind.toUpperCase(); }
}
void main() {
OldGym old = new OldGym();
GymFront front = new GymFront(old, new NewBookings(new OldMembers(old)));
IO.println(front.book("Maya", "Yoga"));
IO.println(front.waitlist("Sam", "Spin"));
IO.println(front.remind("Leo", "HIIT"));
}
new system: Maya (basic) booked into Yoga
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
from dataclasses import dataclass
class OldGym:
def __init__(self):
self.rows = {"MAYA": "MAYA|BASIC", "SAM": "SAM|UNLIMITED"}
def member_row(self, name):
return self.rows[name.upper()]
def waitlist(self, row):
return f"old system: waitlisted {row}"
def remind(self, row):
return f"old system: reminder for {row}"
@dataclass
class Member:
name: str
plan: str
class OldMembers:
"""The adapter at the border: old rows in, plain members out."""
def __init__(self, old):
self.old = old
def find(self, name):
return Member(name, self.old.member_row(name).split("|")[1].lower())
class NewBookings:
"""The new booking code never sees a row."""
def __init__(self, members):
self.members = members
def book(self, name, kind):
member = self.members.find(name)
return f"new system: {member.name} ({member.plan}) booked into {kind}"
class GymFront:
def __init__(self, old, bookings):
self.old = old
self.bookings = bookings
def book(self, member, kind):
return self.bookings.book(member, kind) # moved
def waitlist(self, member, kind):
return self.old.waitlist(self._row(member, kind)) # not yet
def remind(self, member, kind):
return self.old.remind(self._row(member, kind)) # not yet
def _row(self, member, kind):
return f"{member.upper()}|{kind.upper()}"
old = OldGym()
front = GymFront(old, NewBookings(OldMembers(old)))
print(front.book("Maya", "Yoga"))
print(front.waitlist("Sam", "Spin"))
print(front.remind("Leo", "HIIT"))
new system: Maya (basic) booked into Yoga
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
class OldGym {
#rows = new Map([["MAYA", "MAYA|BASIC"], ["SAM", "SAM|UNLIMITED"]]);
memberRow(name) { return this.#rows.get(name.toUpperCase()); }
waitlist(row) { return `old system: waitlisted ${row}`; }
remind(row) { return `old system: reminder for ${row}`; }
}
// The adapter at the border: old rows in, plain members out.
class OldMembers {
#old;
constructor(old) { this.#old = old; }
find(name) { return { name, plan: this.#old.memberRow(name).split("|")[1].toLowerCase() }; }
}
// The new booking code never sees a row.
class NewBookings {
#members;
constructor(members) { this.#members = members; }
book(name, kind) {
const member = this.#members.find(name);
return `new system: ${member.name} (${member.plan}) booked into ${kind}`;
}
}
class GymFront {
#old;
#bookings;
constructor(old, bookings) { this.#old = old; this.#bookings = bookings; }
book(member, kind) { return this.#bookings.book(member, kind); } // moved
waitlist(member, kind) { return this.#old.waitlist(this.#row(member, kind)); } // not yet
remind(member, kind) { return this.#old.remind(this.#row(member, kind)); } // not yet
#row(member, kind) { return `${member.toUpperCase()}|${kind.toUpperCase()}`; }
}
const old = new OldGym();
const front = new GymFront(old, new NewBookings(new OldMembers(old)));
console.log(front.book("Maya", "Yoga"));
console.log(front.waitlist("Sam", "Spin"));
console.log(front.remind("Leo", "HIIT"));
new system: Maya (basic) booked into Yoga
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
class OldGym {
private rows = new Map<string, string>([["MAYA", "MAYA|BASIC"], ["SAM", "SAM|UNLIMITED"]]);
memberRow(name: string): string { return this.rows.get(name.toUpperCase()) ?? ""; }
waitlist(row: string): string { return `old system: waitlisted ${row}`; }
remind(row: string): string { return `old system: reminder for ${row}`; }
}
interface Member { name: string; plan: string; }
// The adapter at the border: old rows in, plain members out.
class OldMembers {
private readonly old: OldGym;
constructor(old: OldGym) { this.old = old; }
find(name: string): Member { return { name, plan: this.old.memberRow(name).split("|")[1].toLowerCase() }; }
}
// The new booking code never sees a row.
class NewBookings {
private readonly members: OldMembers;
constructor(members: OldMembers) { this.members = members; }
book(name: string, kind: string): string {
const member = this.members.find(name);
return `new system: ${member.name} (${member.plan}) booked into ${kind}`;
}
}
class GymFront {
private readonly old: OldGym;
private readonly bookings: NewBookings;
constructor(old: OldGym, bookings: NewBookings) { this.old = old; this.bookings = bookings; }
book(member: string, kind: string): string { return this.bookings.book(member, kind); } // moved
waitlist(member: string, kind: string): string { return this.old.waitlist(this.row(member, kind)); } // not yet
remind(member: string, kind: string): string { return this.old.remind(this.row(member, kind)); } // not yet
private row(member: string, kind: string): string { return `${member.toUpperCase()}|${kind.toUpperCase()}`; }
}
const old = new OldGym();
const front = new GymFront(old, new NewBookings(new OldMembers(old)));
console.log(front.book("Maya", "Yoga"));
console.log(front.waitlist("Sam", "Spin"));
console.log(front.remind("Leo", "HIIT"));
new system: Maya (basic) booked into Yoga
old system: waitlisted SAM|SPIN
old system: reminder for LEO|HIIT
The member app, the front desk and the website made exactly the same calls as before. One feature now lives in new code, and the new code has never seen a MAYA|BASIC row. Next month waitlists move the same way; then reminders; then the old system has no callers left, and it's switched off. Each move is small enough to test, ship, and undo on its own, and the pins from Pin It Down check each one against what the old system did.
How it got its name
Teams replacing big old systems kept landing on this shape: a front, features moved one at a time, the old system shrinking until it could be turned off. The software writer Martin Fowler named it the strangler fig pattern in 2004, after the trees he'd seen growing around old ones in an Australian rainforest. It isn't in the 1994 book of patterns; it's one of the patterns working teams named since. Its two parts are patterns you already know: the front is a facade, and the border is an adapter.
Where you've already used it
- A website moving to a new design one section at a time, where some pages are new and the old ones still work, and the addresses never change. Something in front decides which version answers each address.
- A web API that sends
/bookingsto a new service and everything else to the old one. A reverse proxy or API gateway in front of both is the facade, routing by address. - A phone app that shows new screens for some features and old web pages for the rest, so it could ship before every screen was rebuilt.
When not to use it
- When the old system is small. If it can be rewritten and tested in a week, two systems running side by side for months is the bigger risk.
- When the old system can't be put behind a front, because callers reach into its database directly from everywhere. Then the first job is finding a border, one caller at a time.
- When there's no plan to finish. A strangler fig that stops halfway leaves two systems to run forever. Moving each feature should come with a date.
It costs something too: the facade and the adapter are extra code to keep, the two systems may need to share data while both are running, and the team has to keep track of which feature lives where.
How often you'll meet it: now and then, and on every large replacement project (our estimate).
Check yourself
2 questions to try on the lesson page.
So what
You don't have to choose between living with a tangled system and betting the business on a rewrite. Put one front in front of it, move one feature at a time behind that front, keep the old system's ideas at the border, and switch the old system off when it has nothing left to do.