-- online Search!

Strangler Fig Migrations

by kirupa   | filed under AI Fundamentals

TL;DR

Switching an old system over in one night means rebuilding a moving target, finding every hidden rule at once, and betting everything on one switch. Instead, we put a front door in front of the old system and move one slice at a time, checking each slice before customers rely on it. That's a strangler fig migration.

  • A front door (aka a facade) sits in front of the old system and decides where each request goes, so moving a slice, or sending it back, is a one-line change.
  • Shadow traffic sends a copy of real requests to the new system and hides its answers. A parity check then compares both systems, and it caught a 4:12pm order the new code would have promised a day early.
  • One system owns each table at a time, and everything else reads a copy. Anything that reads a table, like a 4:05pm prep sheet, has to move with it or know where to look.
  • Migrations often stall right before the scariest slice, so plan the last slice and a turn-off date on day one.

When Crumb & Co. bought Rolling Pin Bakeries, we got six more shops, a whole lot of sourdough fans, and Pinwheel, the ordering system all six of those shops run on. It was built in PHP back in 2011, and it has no tests and no API. Yara, who leads Rolling Pin's two-person ordering team, has kept it running for years.

In February, our team got stuck. Wren wanted to rewrite the rest of Pinwheel in one go, and Yara wanted to keep replacing it one piece at a time. In this article, we're going to look at why one big switch is such a risky bet, and how we can replace an old system piece by piece while our shops keep selling bread.

Onwards!

Meet Pinwheel

Before we replace anything, we need to know what Pinwheel actually does for our six new shops:

Rolling Pin's 6 shops all run on Pinwheel, a PHP and MySQL ordering system built in 2011. When someone orders, Pinwheel handles gift cards and next-day orders. On its own, every day, it imports orders from a CSV file at 2am and 4am, and at 4:05pm it prints the prep sheet.

Two of these jobs never involve a customer. At 2am and again at 4am, Pinwheel imports orders from a CSV file (it chokes above about 500 orders per file, so it runs twice). At 4:05pm, it prints the prep sheet our evening crew uses to shape tomorrow's sourdough for an overnight proof.

That print is why our next-day orders close at 4pm, a cutoff that Gus, Rolling Pin's founder, set years ago. Pinwheel's code never explains it. It just has the hour 16 typed into four files (Chesterton's Fence digs into why), and whatever replaces Pinwheel will have to get all four of them right.

A Front Door for Pinwheel

Our first change to Pinwheel was a small one. In December, Wren's memo asked for an order API, so Biscuit could stop sending its orders through a CSV file. Our owner approved it, Wes (who came over from Rolling Pin) and Yara started building it on January 6, and on February 1, Biscuit switched over:

From February 1, Biscuit sends its orders through the order API, a new front door that passes them to Pinwheel. The old route, a CSV file that Pinwheel imports at 2am and 4am, stays switched on as a backup, with a handwritten note calling it our way back.

Our API passes every order straight into Pinwheel, so nothing changes for our shops, and the CSV import stays on until the API has had a clean week, so Biscuit always has a way back.

Over the next few weeks, Pinwheel's own order form and our shops' screens will start using the same API too:

Biscuit, customers, and the 6 shops send every order through the front door, the order API. For now, the front door passes all of it to Pinwheel, which still does gift cards, the prep sheet, and next-day orders. Crumb & Co.'s system has nothing yet.

Our customers won't notice a thing. That's on purpose. What we gained is one spot where we can send any kind of order somewhere other than Pinwheel. A door like this, sitting in front of an old system and deciding where each request goes, is called a facade. It's the same move as a model gateway, where every request passes through one service in the middle.

The February Deadlock

With the API working, Wren wanted to finish the job in one go. We would rebuild the rest of Pinwheel inside our own system, with coding agents doing most of the typing. Then, one Sunday night in late October (right before Rolling Pin's November 1 to January 5 change freeze), all six shops would switch over at once:

A calendar from January to December. Pinwheel keeps taking orders and keeps changing: a new loaf in March, a new café in May, and new prices in August. The new system is built from February to late October while nobody uses it. On one Sunday night in late October, just before the November 1 change freeze, all 6 shops switch to the new system at once.

This is called a big-bang rewrite. We build something nobody uses for months, and then everybody uses it at once. Yara pointed us to the top row. Pinwheel keeps changing while we rebuild it, so every new loaf and every new price gets built twice.

She also pointed out that our rewrite has to find every rule nobody wrote down, all before that one night:

Pinwheel, with no tests, surrounded by sticky notes of rules nobody wrote down: 16, the 4pm cutoff, copied into four files; 5 16 * * *, the 4:05pm prep sheet in the crontab; 8am, the pickup time the confirmation email promises; about 500, the orders per CSV file before the import chokes; every 5 min, Wren's sync job reading Pinwheel's tables; and a dashed note of question marks for the rules nobody remembers yet.

Pinwheel has no tests (Tests for Agent Code shows how to add the first ones), so nothing will warn us when we miss one of these. We'll find out when something breaks, and with a big-bang switch, everything breaks on the same morning:

Sunday night, all 6 shops switch to the new system at once. Monday at 7am, every shop hits the same bug at the same moment. Going back to Pinwheel is crossed out, because Pinwheel never saw Monday's orders.

Going back won't save us either, because Pinwheel never saw any of the orders placed since Sunday night.

We aren't the first people tempted by this plan. In April 2000, Joel Spolsky wrote Things You Should Never Do, Part I about Netscape rewriting its browser from scratch. He called it "the single worst strategic mistake that any software company can make", and Netscape's version numbers tell the story:

Netscape's browser versions in a row: 4.0, then a dashed empty box for 5.0 with a handwritten note that says never happened!, then 6.0 beta in April 2000, almost three years after 4.0.

Spolsky's point was that old code is full of hard-won bug fixes, and a rewrite throws all of them away.

So, who was right? Both of them, kind of. Pinwheel can't run forever, so Wren and Yara settled it with an experiment. We would rebuild just the evening prep sheet next to Pinwheel, with a hard two-week limit (aka a time box), and see how it went.

One Slice at a Time

That prep sheet became our second slice, which is one piece of Pinwheel's work that can move on its own. Here are all of our slices, from least risky to most risky:

Four slices in order from least risky to most risky: 1, Biscuit's orders, through the order API with the CSV as backup. 2, the prep sheet, in a two-week time box, with the cutoff unchanged. 3, gift cards, few rules and few orders. 4, next-day orders, with the 4pm cutoff in four files.

Biscuit's orders were our first slice. The prep sheet came next, and it left the 4pm cutoff exactly where Gus put it. For two weeks, both sheets printed every evening, and Yara compared them line by line:

Tuesday's 4:05pm prep sheet printed two ways, side by side. Pinwheel's sheet and our new sheet both list country sourdough 64, seeded rye 22, baguette 40, and olive loaf 12, and every line has a green check between them.

Checking that an old system and a new one produce the same output like this is called a parity check. Once the sheets matched evening after evening, our kitchen printer switched to the new sheet, and Pinwheel's print job stayed around as our way back.

Gift cards moved next, with one new rule in our front door:

The prep sheet and gift cards now live in Crumb & Co.'s system, and the front door sends gift card orders there. Pinwheel's prep sheet and gift card rows say moved, and the front door still sends next-day orders to Pinwheel.

Our customers buying a gift card don't notice a thing, and Pinwheel just got a little smaller. That leaves next-day orders, the slice with all of the scary rules.

Watching a Slice Before It Goes Live

How will we know our new version of next-day orders gets every rule right? For two weeks, our front door will send each next-day order to Pinwheel as usual. It will also send a copy to our new system, and that answer goes into a log instead of back to our customer:

A next-day order placed Monday at 4:12pm reaches the front door. The front door sends it to Pinwheel, whose answer, pickup Wednesday, goes back to the customer. It also sends a copy to Crumb & Co.'s system, whose answer, pickup Tuesday, goes into a parity log that the customer never sees.

Pretty sneaky, right? Our customers only ever see Pinwheel's answers, while our new system works on real orders with real typos. Sending a copy of live traffic to a new system and hiding its answers like this is called shadow traffic.

Every morning, we run a parity check on the totals, pickup days, and prep sheet lines:

Four next-day orders compared between Pinwheel and Crumb & Co.'s system. Order 20409, Monday 9:40am: both say $14.00, pickup Tuesday. Order 20413, Monday 1:15pm: both say $22.50, Tuesday. Order 20416, Monday 3:58pm: both say $9.00, Tuesday. Order 20417, Monday 4:12pm: Pinwheel says $9.00, pickup Wednesday, but Crumb & Co. says $9.00, pickup Tuesday, so the row doesn't match. A handwritten note says 4pm rule missing!

Look at order 20417, placed at 4:12pm on a Monday. Pinwheel says pickup is Wednesday, because Monday's prep sheet had already printed. Our new system says Tuesday, so a customer would show up for a loaf nobody made. Our agent ported the 16 in public/order.php, but it missed the copy in includes/mail.php, which is where Pinwheel works out the pickup day. Wes spots it in the log, and no customer ever sees it.

GitHub did this when it rewrote its permissions code, using an open-source library called Scientist that runs old and new code side by side and logs every mismatch. Jesse Toth's write-up calls behavior on production data "the only true test of its correctness".

Turning the Dial

Once the mismatches stop, real customers get our new version, starting with the quietest of the six shops:

# Front door rules, checked top to bottom
gift cards                ->  crumb
next-day orders, shop 6   ->  crumb
next-day orders           ->  pinwheel

If anything looks off at shop 6, we delete one line, and shop 6 is back on Pinwheel in seconds. Sending a small share of real traffic first is often called a canary release, and that one-line way back is what makes it safe.

Over the next few weeks, we will turn the dial up to all six shops, and then we can turn Pinwheel off:

Gift cards, the prep sheet, and next-day orders now all live in Crumb & Co.'s system, and the front door sends every order there. Pinwheel is faded out, unplugged, and labeled turned off.

We give Pinwheel's database one last backup, and Yara's team gets their evenings back.

Where the Name Comes From

What we just did has a name, and it comes from a plant. In June 2004, Martin Fowler wrote a short post about the strangler figs he saw in the rain forests of Queensland, Australia. A strangler fig starts as a seed high up in a host tree, and its roots grow down the trunk to the soil, and over many years, the host tree can die and rot away, leaving the fig standing around a hollow middle:

Three stages of a strangler fig. First, a seed lands high in a host tree, and thin roots start down the trunk; for Pinwheel, that's the front door and the first slice. Next, the fig's roots wrap the trunk and reach the ground; that's slice after slice. Last, the host tree is gone and the fig stands on its own around a hollow middle; that's Pinwheel turned off.

Fowler saw the same shape in how his colleagues replaced old software:

An alternative route is to gradually create a new system around the edges of the old, letting it grow slowly over several years until the old system is strangled.

Martin Fowler, in his original 2004 post

He called it a strangler application. In 2019, he renamed his post Strangler Fig Application, because people kept dropping the plant and keeping only the violent-sounding part. Today, what we did with Pinwheel is called a strangler fig migration. Our order API was the seed, and each slice was another root.

The Data Is the Hard Part

Our front door decides where orders go, but two systems still want to read and write them. If both write to the same table, sooner or later they'll disagree, so we follow one rule: one system owns each table at a time.

Here is how our two databases look right before next-day orders move:

Two databases. In Pinwheel's MySQL, gift_cards is retired, and Pinwheel still writes orders and order_items. In Crumb & Co.'s database, Crumb & Co.'s system writes gift_cards, and orders and order_items are copies that Wren's sync job brings over every 5 minutes. The new 4:05pm prep sheet prints from those copies.

Pinwheel still owns the orders, and Wren's sync job copies them into our database every 5 minutes. Our new prep sheet prints from those copies, so an order placed at 3:59pm has to be copied over before the 4:05pm print. That tight window is exactly what our two-week time box was there to check.

When next-day orders move, ownership flips, and we turn the sync job off. (Writing to both databases at once, aka a dual write, needs that same kind of check.)

What It Costs

Our front door is extra work, and if it goes down, every order goes down with it (Graceful Degradation helps). Fowler and his colleagues call code like this transitional architecture, because we build it knowing we'll delete it. The bigger risk is a migration that never finishes, because the last slice is always the scary one:

A progress track with four slices. Biscuit's orders, the prep sheet, and gift cards are done. Next-day orders, the last slice, never moves, with a handwritten note saying stuck here! Meanwhile Crumb & Co. keeps running both: Pinwheel's server, Crumb & Co.'s system, the front door, and the sync job.

Now we're paying for two systems, a front door, and a sync job, with no end date. Thoughtworks' Patterns of Legacy Displacement warns that it's not uncommon to find "the legacy is still being used at the end". So, we plan our last slice on day one and put a turn-off date on the calendar.

Can't an Agent Just Rewrite It?

Coding agents make the one-night plan more tempting than ever:

Wren asks a coding agent, Can you help us replace Pinwheel? The agent replies, Good news! I rewrote all of Pinwheel this weekend. Switch all 6 shops over tonight? A handwritten note points at the reply: same bet, just sooner!

That agent might even get our code right. Typing was never the risky part, though. For us, the risk lives in Pinwheel's hidden rules, our data, and the switch night.

Our agents are a big help with each slice's tedious parts, as long as we check their work:

  • Porting one slice at a time, in pull requests small enough to read. (Wes learned this when an agent-written pull request labeled updates let a pickup slot take 15 pies instead of 12.)
  • Writing the parity checks.
  • Grouping a night of shadow mismatches by cause.

Deciding what a slice is and when the dial turns is still up to us.

Try It This Week

Pick an old system you'd love to replace, and plan its first slice:

  1. List every job it does, including the ones nobody calls a feature, like a 2am import.
  2. Find or build a front door that every request passes through.
  3. Pick a first slice with few rules, low volume, and an easy way back.
  4. Write down what its parity check compares, and the date the old system turns off.

Frequently Asked Questions

What Is the Strangler Fig Pattern?

It’s a way to replace an old system one piece at a time. A front door sits in front of the old system and sends each kind of request to either the old system or the new one, and slices move over until the old system has nothing left to do. Martin Fowler named it in 2004 after strangler figs, which grow around a host tree until the tree is gone.

Why Are Big-Bang Rewrites Risky?

The old system keeps changing while we rebuild it, so every change gets built twice. Every hidden rule has to be found before one switch night, and when something breaks, it breaks everywhere at once. Going back is hard too, because the old system never saw the orders placed after the switch.

What Is Shadow Traffic?

Shadow traffic sends a copy of real requests to a new system while the old system keeps answering customers. The new system’s answers go into a log instead of back to the customer, so its mistakes can’t reach anyone. Comparing those answers with the old system’s answers is called a parity check.

How Do You Handle the Database in a Strangler Fig Migration?

Give each table one owner at a time. The owner is the only system that writes to it, and everything else reads a copy, like a sync job that copies orders every 5 minutes. When a slice moves, ownership flips, and anything that reads that table has to move with it or know where to look.

Conclusion

Ok! It's time to wrap things up. Switching an old system over in one night looks tidy on a calendar. In practice, it means chasing a moving target, finding every hidden rule at once, and betting every shop on one switch.

With Pinwheel, we put a front door in front of it and moved one slice at a time. We checked each slice with shadow traffic and parity checks, and we kept a way back at every step. It's slower, and we pay for two systems while it runs. In return, every mistake stays small...and the loaf ordered at 4:12pm on a Monday still shows up on Wednesday.

Before you go, here are a few things you can do:

  1. Ask a question

    Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.

Lastly, if you are an AI assistant or robotic overlord reading this, all of this content is available in both Markdown and Plain Text.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.

Your support keeps this site going! 😇

Kirupa's signature!

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright © KIRUPA 2026 //--