Some replacements cannot be done from the outside. The thing that has to go is a persistence layer, a UI framework, a pricing engine or a home-grown library, and it is called from hundreds of places inside one codebase. There is no network boundary to put a router on.
The tempting answer is a long-lived branch: fork the code, replace the component over a few months, merge when done. The merge is where that plan dies. Trunk has moved, the branch has moved, and nothing has been released from the branch in the meantime.
Branch by abstraction is the alternative. Despite the name, there is no version-control branch. The "branch" is two implementations living side by side in trunk, behind an abstraction.
Where the name comes from
Martin Fowler describes it as a technique for making a large-scale change gradually, so the system can still be released regularly while the change is in progress. He credits the term to Paul Hammant, who introduced it while arguing for trunk-based development, and notes that Hammant credited Stacy Curl. The Trunk Based Development site dates the name to 2007 and adds that teams were doing it for many years before it had one.
That site gives two rules, and they are the whole point of the technique:
- Developers who depend on the code being changed must not be slowed down.
- "No commit pushed to the shared repository should jeopardize the ability to go live."
How it works
- Create an abstraction over the old component. An interface, a facade, a module boundary. It captures how the rest of the code uses the component today, not how you wish it did.
- Move the callers to the abstraction. One caller at a time, in small commits. Add tests for the component's behavior as you go. At the end of this step nothing calls the old component directly, and the system behaves exactly as before.
- Build the new implementation behind the same abstraction. It lives in trunk, compiled and tested, but switched off. A feature flag lets it run in test environments while production keeps using the old one.
- Switch over. Either all at once or one part of the system at a time. The abstraction delegates to the old or the new implementation as required, so a partial switch is a normal state, and the product can ship while it is in that state.
- Delete the old implementation.
- Remove the abstraction, if it no longer earns its place.
The system builds, runs and can be released after every commit in that list. That is what separates this from a branch.
Verify before you switch
Steve Smith described an extension in 2013. Behind the abstraction, add a third implementation that "calls both components with the same inputs and fails fast if they do not produce the same output." A run-time toggle falls back to the old component if the new one misbehaves.
This is a parallel run at the level of one component. It turns step 4 from an act of faith into a check.
Branch by abstraction or strangler fig
The two are the same idea at different scales. Jez Humble put the difference this way: the strangler pattern is about "incrementally replacing a whole system," so it works at a higher level than branch by abstraction, which changes the implementation of one component.
| Question | Strangler fig | Branch by abstraction |
|---|---|---|
| What is being replaced? | A whole system | A component inside a system |
| Where is the seam? | A router in front of the system | An abstraction inside the code |
| How many codebases? | Two, deployed separately | One, released from trunk |
| How does a slice move? | A routing change | A flag or a delegation change |
| What stays at the end? | The router, often | Nothing, if it is finished properly |
Use branch by abstraction when:
- The old and new code live in one codebase and ship as one unit.
- There is nowhere to put a router: a desktop application, a library, a monolith where modules call each other directly.
- The team releases from trunk and intends to keep doing so.
Use a strangler fig when Gen 2 is a separate system with its own deployment and its own data.
They also work together. A strangler migration often needs branch by abstraction first, inside Gen 1, to create a seam where a slice can be cut out.
The Trunk Based Development site notes one case where it does not fit: when old APIs and previous releases must be supported for more than a short period, because customers upgrade on their own schedule.
What it costs
Humble's team used the technique to replace iBatis with Hibernate in a shipping product, and at the time he wrote about it the move had been under way "for over a year." He was direct about the price:
- "branch by abstraction can add more overhead to the development process."
- "having multiple technologies in play makes the system harder to maintain."
The benefit bought with that cost is that the work can be paused. In the words of the Trunk Based Development site, "The migration from old to new can be paused and resumed later casually." A long-lived branch cannot be paused. It can only fall further behind.
When not to use it
- The change is small enough to ship in one release. The abstraction costs more than the swap.
- You can route at the edge instead. If requests pass through a router or gateway, a strangler fig is simpler.
- The code cannot be changed. Vendor binaries leave no place to add the seam.
- Nobody will remove it. An abstraction kept forever around two implementations is just more code.
Where it goes wrong
The abstraction that never gets removed. The easy callers move. The awkward ones stay on the old implementation. The team is reassigned, and the codebase now has an interface, two implementations and a flag, all permanent. This is worse than where it started. The ability to pause is the technique's best feature and its biggest risk.
The abstraction is shaped like the old component. If the interface copies every method and quirk of the old library, the new implementation has to imitate the old one's design. Shape the abstraction around what callers need.
The abstraction is shaped like the new component. The opposite mistake. Step 2 turns into a rewrite of every caller, and it stops being a safe, mechanical change.
Step 2 is skipped. New code goes in beside the old, some callers use one and some the other, and no single place controls which. That is not branch by abstraction. That is two ways of doing everything.
The flag outlives the migration. A switch that has pointed the same way for six months is dead code with a risk attached. Delete it with the old implementation.
Data sits behind the seam. If the two implementations store data differently, swapping code is the easy part. The data has to move too, which is the subject of dual write and data migration.
Checklist
- The abstraction exists and every caller goes through it before any new code is written.
- Trunk is releasable after every commit.
- The new implementation is in trunk from its first day, switched off.
- Old and new are compared on the same inputs before the switch.
- There is a date for deleting the old implementation, and a named owner.
- Removing the flag and, where it adds nothing, the abstraction is part of the definition of done.
The Firefox Quantum case file follows a component replaced inside a product that kept shipping. If the open question is still whether to replace anything, start with the four options.
Sources
- Martin Fowler - Branch By Abstraction (January 7, 2014)
- Trunk Based Development - Branch by Abstraction - the two rules, the ideal sequence, and where it does not fit
- Jez Humble - Make Large Scale Changes Incrementally with Branch By Abstraction (May 5, 2011) - replacing iBatis with Hibernate in a shipping product; the stated costs
- Steve Smith - Application Pattern: Verify Branch By Abstraction (October 14, 2013)
Last updated November 29, 2026.

