Feature flag vs feature branch: two ways to pay for unfinished code
A branch keeps unfinished code off main and sends the bill on merge day. A flag ships it dark and bills you every day until it is deleted. How to choose, with the arithmetic for both.
Buse Senol9 min read

On June 12, 2025, a code path in Google Cloud's Service Control crashed in region after region. The code had shipped two weeks earlier without a feature flag. A feature flag keeps unfinished or risky code inside main but switched off; a feature branch keeps it outside main until it merges.
Google's incident report tells the story plainly. On May 29, a new feature added quota policy checks to Service Control. The release went out region by region, but the new code path never ran during that rollout, because only a particular kind of policy change could trigger it. The change came with a kill switch, which Google calls a red-button, for that serving path, but in the report's words, it "did not have appropriate error handling nor was it feature flag protected." Two weeks later, at about 10:45 in the morning Pacific time, a policy change with unintended blank fields was written to a regional Spanner table and copied to every region within seconds. Every region read the blank fields, hit a null pointer, and sent its binaries into a crash loop. Engineers found the cause within 10 minutes and had the red-button rolled out within 40. Most regions recovered within two hours, but us-central1 took much longer, and the incident ran from 10:51 to 18:18. Google's own conclusion is the reason this piece exists: "If this had been flag protected, the issue would have been caught in staging."
Unfinished code always costs something while it waits. A branch keeps it outside main and sends the bill on merge day, when everything that changed in the meantime has to be reconciled at once. A flag keeps it inside main, in production, and sends a smaller bill every day until the flag is deleted. The right choice depends on which bill your team can see and is willing to pay.
To make the bills concrete, this piece follows one feature through both paths. Picture a team that needs three weeks for a new checkout step, in a monorepo where the whole company merges about 40 changes a day. The numbers are illustrative; the arithmetic is the point. After that, two more real incidents, at Harness in 2025 and at Knight Capital in 2012, show the other two ways a flag fails.
Two places to keep unfinished code
Unfinished code has to live somewhere while it is being written, and there are only two places for it. Martin Fowler's Patterns for Managing Source Code Branches describes them as two integration patterns. In feature branching, work stays on its own branch and is integrated with the mainline only when the feature is complete. In continuous integration, developers merge small pieces into the mainline frequently, and the unfinished feature is hidden from users until it is ready. Fowler's first suggestion for hiding it is not a flag at all. He suggests building the logic first and connecting the user interface last, and reaches for feature flags only when there is no easy way to hide the partial feature.
A flag, in other words, is what makes continuous integration possible for work that cannot be hidden any other way. It separates deploying code from releasing behavior: the code runs in production, but users cannot reach it until someone turns the flag on. Our earlier piece on progressive delivery covers what that separation does for rollouts. This piece is about the earlier decision: whether a given change should wait on a branch, wait behind a flag, or not need to wait at all.
What a branch costs: the bill on merge day
Our team puts the checkout feature on a branch. It takes 15 working days, and during those days the rest of the company keeps merging into main at 40 changes a day. By merge day, 600 changes have landed on main that the branch has never seen. Most of them touch code the feature does not care about. Suppose 2% of them touch code the feature also touches, which is a guess but not an extreme one for a busy monorepo. That is about 12 changes to reconcile, all at once, on the day the team wants to ship, and the people who wrote them have moved on to other work.
Git shows some of those 12 as conflicts, and those are the easy ones. The expensive ones merge cleanly and still break. Fowler calls them semantic conflicts and gives the canonical example: "Imagine Scarlett changes the name of a function, and Violet adds some code to her branch that calls this function under its old name." No line conflicts, the merge succeeds, and the build fails, or worse, it builds and fails at run time. On merge day the branch's three weeks of work are tested together with main's three weeks of work for the first time, so every semantic conflict surfaces at the same moment.
Now run the same feature without a long-lived branch. If the team merges its work into main every day, it meets about 0.8 overlapping changes a day instead of 12 at the end, because 40 changes times 2% is 0.8. Each one is reconciled while both authors still remember what they wrote. The total amount of overlap is the same, but it arrives in small pieces instead of one batch, and a small piece is cheap to fix.
The DORA research program reached the same conclusion from survey data. Its trunk-based development guidance, based on its 2016 and 2017 survey data, links higher delivery and operational performance to three habits: keeping three or fewer active branches, merging into trunk at least once a day, and having no code freezes or integration phases. So the branch's bill grows with the branch's age. A branch that lives for a day is nearly free, while a branch that lives for three weeks turns merge day into an integration phase.
What a flag costs: a bill every day
Now the team takes the other path. It merges the checkout work into main every day, behind a release flag that stays off in production. The merge-day bill disappears, but three smaller bills arrive in its place, and they keep arriving for as long as the flag exists.
The first bill is testing. While the flag exists, the checkout code has two live paths, and both have to work. Pete Hodgson's Feature Toggles, still the reference on the subject, puts it directly: a single toggle means doubling at least some of the testing, and "with multiple toggles in play we have a combinatoric explosion of possible toggle states." If two other flags touch the same checkout flow, the code now has eight possible states, because three on-off switches give two to the third power combinations. Nobody tests all eight, so some of them will only ever run in production.
The second bill is inventory. Hodgson writes that release toggles should usually be gone within a week or two, and that "savvy teams view their Feature Toggles as inventory which comes with a carrying cost." Inventory follows a simple rule from queueing theory, Little's law: the average number of flags in a codebase equals the rate at which flags are added multiplied by how long each one lives. If a team adds five flags a week and deletes each one two weeks after launch, it carries about 10 flags at any time. If deletion slips to ten weeks, because nobody owns it, the same team carries about 50, with nothing else about its work having changed. Uber's experience shows the real scale. Its Piranha tool, which writes the code changes that delete stale flags, generated cleanup changes for 1,381 flags between December 2017 and May 2019, which the paper says was 17% of all flags; 65% of those changes landed without any edits.
The third bill is the switch itself. A flag is a branch that lives in production, and it can be flipped, deleted or reused by someone who does not know what is behind it. That bill is the one that shows up in incident reports.
Three ways a flag fails
The first way is the Google incident: a risky code path with no flag at all. Google's report explains what the flag would have done: at Google, flags turn a feature on gradually, region by region and project by project, starting with internal projects, so that problems surface early. The code was deployed region by region, but deploying is not the same as enabling, and the dangerous path was enabled everywhere at once by a data change. One of Google's remediation items follows from that: "We will enforce all changes to critical binaries to be feature flag protected and disabled by default."
The second way is deleting a flag that is still in use. On October 31, 2025, IDP pipelines on Harness Cloud failed in its Prod1 environment. A flag originally added for an internal migration had been archived during a routine cleanup, and the IDP service still evaluated it. The reason the cleanup thought the flag was unused brings this piece's two subjects together: "the archival validation process only verified references within a limited set of code branches." The flag was gone from the branches the cleanup checked, but it was still read by code on a branch it did not check. Harness restored the flag to recover, and among its action items it extended the validation to every major repository and release branch.
The third way is keeping a flag after its code is dead and then reusing it. In 2012, according to the SEC's order against Knight Capital, the firm deployed new order-routing code that "repurposed a flag that was formerly used to activate the Power Peg code," a feature Knight had stopped using in 2003 but never deleted. A technician did not copy the new code to one of the eight servers, so on that server the old flag woke up the old code. In about 45 minutes, the order says, Knight's system produced 4 million executions in 154 stocks for more than 397 million shares, and Knight lost over $460 million.
The three incidents share one lesson. None of them was caused by flags as a technique. Each was caused by a gap in the flag's life: it was never created, it was deleted while still in use, or it outlived its code. So the daily bill of a flag is mostly the cost of managing that life, and a team that does not pay it ends up paying for an incident instead.
A third option: neither
Many changes need neither a long-lived branch nor a flag. Fowler's branching article describes two techniques that hide unfinished work through the structure of the code. The first is the Keystone Interface. His example is an insurance form that asks claimants whether they smoke: the team builds and tests the logic behind the question in main and adds the question to the user interface on the last day. Until then, no user can reach the new logic, so no flag is needed. The second is Branch by Abstraction: the team puts an interface in front of the code it wants to replace, builds the new implementation behind that interface in main, and switches over when the new one is ready.
Both techniques depend on the code being modular enough to allow them, and Fowler draws the conclusion bluntly: "Feature Branching is a poor man's modular architecture." When a codebase makes it hard to hide work behind an interface, teams fall back on branches or flags. The longer-term fix is the modularity, because it removes the need for both.
Choosing, change by change
The choice is not made once per team. It is made per change, and the deciding questions are how long the work will take, whether users could reach it before it is ready, and what happens if it misbehaves in production.
| Change | Where it waits | Why | What it costs |
|---|---|---|---|
| A fix or small change finished within a day | A short branch, merged the same day | Nothing unfinished reaches main | Almost nothing, if the branch really lives under a day |
| A multi-day feature with a new user-facing entry point | Main, with the entry point connected last (Keystone Interface) | Users cannot reach the logic until the last change | Discipline about the order of work |
| A multi-day feature that cannot be hidden by structure | Main, behind a release flag that starts off | Daily integration without exposing users | Double testing, an owner, an expiry date, and the deletion |
| Replacing an internal component | Main, behind an abstraction (Branch by Abstraction) | Old and new run side by side until the switch | An interface that may outlive the migration |
| A risky change to a critical path, especially one triggered by data | Main, behind an operational flag, off by default, enabled region by region | It can be turned on gradually and off quickly | A flag that may need to live longer, so document it |
| A long-lived release line, such as a mobile version | A release branch, not a feature branch | The release needs stabilizing, not the feature | Back-porting fixes |
What to change on Monday
Start with two counts. First, list every active branch in your main repositories with its age. Any feature branch older than a few days is accumulating a merge-day bill, so for each one, ask which row of the table above it belongs in. Second, count your feature flags and check each one for an owner, a creation date and an expiry date. Then apply Little's law: multiply the number of flags you add per week by the number of weeks a flag is supposed to live, and compare the result with your count. If the real count is much higher, your flags are living far longer than planned, and deletion needs an owner.
Then change two habits. Before deleting a flag, search every repository and every release branch that could read it, not only main, because Harness's outage came from a cleanup that checked too few branches. And for any change to a code path that only runs when data or configuration changes, add a flag that starts off and is enabled gradually, because a region-by-region deploy does not test code that the deploy never runs. Google's Service Control change passed a careful rollout and waited two weeks for the data that would break it. A branch would not have helped, since the code had already merged and shipped. What was missing was a way to switch that path on slowly and off quickly, and that is the bill a flag is worth paying, provided someone also pays the bill to delete it.
Comments
Loading comments…