
Feature Flag Debt: The Life After Rollout
Flag removal fails structurally, not from indiscipline — an expired flag gives no signal of its own while both paths keep working. What it costs, how to detect it, how to delete it.
TL;DR: Flag removal fails for a structural reason, not because engineers lack discipline. The flag is most interesting on the day it is introduced and least interesting on the day it should die — and an expired flag gives no signal of its own: both paths keep working and nothing in the code points at it, even though stale flags can still interfere with other experimental flags and cause bugs. The cost is not the if statement, it is the state space. This piece covers what the flag has to carry at birth to make staleness detectable, three detection routes and the honest limit of each, and the removal commit as its own shape: pin, verify, delete.
Removal fails for a structural reason, not a discipline reason
A team that has flags can end up with a graveyard of them, and it is easy to read that as a failure of the team's discipline. It is not. Look at the incentives.
The flag is most interesting on the day it is introduced. It is the mechanism carrying the work everyone is watching, the thing that lets the branch ship, the subject of the ramp. It is least interesting on the day it should die — the rollout succeeded, the feature is now just the product, and the person who wrote it is three tickets away. Nothing in the code is left pointing at the branch.
Now compare it to other kinds of debt. A missing index makes a page slow enough that someone files a ticket. A leak makes a process fall over at 4am. A broken contract goes red in CI. Duplicated logic diverges and produces a bug. Each of these can announce itself, because each can eventually hurt.
An expired flag gives no signal of its own. The code works. Both paths work. The flag reads true every time it is asked and will keep doing so until someone removes it. That does not make it harmless: Uber's Piranha documentation lists, among the drawbacks of code left behind by stale flags, that the flags can interfere with other experimental flags and that stale flags can also cause bugs. But nothing in the code itself marks the flag as stale, which is why this debt accumulates.
Naming this as structural matters because it tells you where the fix has to live. If the problem were discipline, the answer would be a reminder. Because the problem is that intent evaporates, the answer is that the flag must carry its own expiry — since no downstream process, tool, or well-meaning colleague can reconstruct what the author never wrote down.
What the expired flag actually costs
The usual accounting is wrong. People count the conditionals, decide that a dozen stale if statements is not much code, and conclude the debt is theoretical. A stale branch is genuinely cheap to read once.
The cost is the state space. Every flag still live doubles the number of configurations that the next reader, the next test, and the next refactor must hold as possible. Ten forgotten flags do not cost ten branches — they cost a codebase in which nobody can say with confidence what is actually running in production.
The second-order effects are where it bites, and they are all the same shape: something that should be a local decision becomes impossible without global knowledge nobody has.
A refactor cannot simplify a branch that might still be reachable, so the simplification does not happen and the shape of the code stays wrong. A test suite cannot drop a combination that might still exist in production, so the combination stays covered and the suite keeps paying for a path nobody uses. An incident responder cannot rule out a code path that is still wired, so the search space during an outage includes behavior that has been dead for a year.
One distinction is worth being precise about, because it is where this work meets the general craft of deleting code. In the sense used here, dead code is unreachable — and that is what lets tooling find it. A stale flag is the opposite: it is entirely reachable, on both sides, and that reachability is the whole hazard. The general craft of proving code dead and removing it belongs to the refactoring literature. What is specific here is that the branch is live by construction and only the declaration says it should not be.
Making staleness visible in the code
The minimum a flag carries at birth is three things: its type, an owner, and a removal condition.
The type comes from the taxonomy, and it is doing the load-bearing work — it says whether this flag is in the debt frame at all. The owner is a name, because a flag with no owner has nobody responsible for deleting it. The removal condition is either a date or a stated event: "when the rollout reaches full traffic", "when the legacy importer is retired". An illustrative sketch, written as a fragment of a function body:
// type: release | owner: checkout | remove-when: rollout reaches 100% (target 2026-09)
if (flags.newCheckoutSummary) {
return renderSummaryV2(order)
}
return renderSummary(order)That comment is not documentation. It is a machine-readable statement of intent that stays with the code, and every sweep, report, or cleanup that runs on the code reads it or guesses.
In-code beats a ticket or a dashboard for one unglamorous reason: it travels. The flag will be moved to another file, renamed during a refactor, and wrapped in something else. Through every one of those, the comment stays attached to the branch it describes. A ticket does not follow the code, and by the time the flag is stale the ticket may already be closed. A dashboard is a second system with its own drift, and the entry describing this flag may have been written by someone who has since left.
The permanent-flag corollary, stated plainly because this is where cleanup enthusiasm does damage: kill switches and permission gates that are declared permanent are outside the debt frame entirely. Ops toggles as a whole are not: Pete Hodgson's feature-toggles article says that most ops toggles will be relatively short-lived and that, once confidence is gained in the operational aspects of a new feature, the flag should be retired; however, it also says it is not uncommon for systems to have a small number of long-lived kill switches, which let operators of production environments gracefully degrade non-vital system functionality when the system is enduring unusually high load. An emergency lever that has never been thrown is not stale — it is a lever for an emergency that has not happened. Deleting it because a report flagged it as untouched for a year is the mirror-image failure, and it becomes a risk once a team gets serious about flag debt.
Detection: from the record to a signal
Three routes exist. Each has an honest limit, and the limits are the reason a team needs more than one.
The declared expiry read from code is cheap — a grep and a date comparison — and it is only as good as the declaration. If the comment says "remove after the March rollout" and the rollout slipped, the route reports a false positive. If nobody declared anything, the route reports nothing at all.
The flag's own evaluation record — a value that has not varied in a long time — needs data from the delivery side, which means it only works for flags that go through a system that records evaluations. Build-time constants are invisible to it.
A search for evaluation sites with no remaining callers catches branches that have been orphaned by other refactors. It finds the code, not the intent: a flag that is still evaluated but always returns the same thing looks perfectly alive.
The one that generalizes is the declared expiry, because, unlike the evaluation record, it works before any traffic exists, and it is the only one of the three that reports intent rather than behavior. The other two are corroboration.
Which brings up the judgment that matters. A flag stuck at one value is a candidate, not a verdict. A permission gate for a plan nobody in the current cohort is on evaluates to false every single time for as long as that stays true, and, in its evaluation values alone, looks identical to a dead release toggle. Only the declared type tells them apart — and a sweep that deletes on the evidence of a stuck value alone can end up deleting the entitlement check for your enterprise tier.
The removal commit as its own shape
The removal is a behavior-preserving edit against the winning path plus a deletion of the loser. That makes it a refactor-shaped commit, and it should carry nothing else — no fix riding along, no small improvement to the code you are already touching. The general principle of keeping behavior changes out of refactor commits belongs to the refactoring literature; what is flag-specific is the order.
Pin first. Stop evaluating and hard-code the value the flag has settled on. This is a small, obviously-safe commit that makes the next steps boring.
Verify the pinned state in production. The flag is no longer being consulted; confirm that what is running is what you think is running, before deleting the ability to change your mind.
Then delete the branch and the flag definition together. Both sides of the conditional collapse to the winner, and the flag disappears from wherever it was defined.
Then delete the code the loser owned. This is the step that is genuinely a judgment call, and it is deliberately last.
Which is where the honest limit on tooling lands. Automated flag removal can do the middle steps — it can find the conditional, collapse it to the winning side, and delete the definition. Whether the loser's code is still reachable through some other path is a question about what else in the system calls it and why; confirm what your removal tool documents about that judgment instead of assuming the tool makes it. The deletion still needs a reader. What automation buys is that the reader arrives at a small, well-shaped diff instead of an archaeology problem.