Video in progress
Feature flags have piled up over the years and the code now has hundreds of `if (flags.isOn(...))`. How do you manage this debt across several teams?
When a flag is created, you record its type (release, experiment, ops kill switch, permission), its owner and an expiry date. Expired release flags automatically produce a ticket and a warning, and in code the flag check is gathered at a strategy selection point instead of being scattered through business logic.
📖 Answer
A flag is a strategy that switches at runtime. One flag is harmless, but 300 flags multiply the number of code paths combinatorially: nobody has tested all the combinations, and one day a strange mix of two old flags breaks prod.
Not all flags are the same, and formalizing that difference is the first step:
- release flag: for deploying new code hidden. Lives for weeks. Most of the debt is here;
- experiment: an A/B test. Removed as soon as the experiment ends;
- ops / kill switch: turning off a heavy feature under load. Lives long, and that's normal;
- permission: a feature by plan or customer. This is really configuration, and it may not belong in the flag system at all.
The process:
- When creating a flag, the owner and
expiresare mandatory fields. The flag service (Unleash, LaunchDarkly or your own) requires this. - For expired release flags, a bot opens a ticket for the owner. A weekly report shows the number of "dead flags" by team.
- The metrics show when each flag was last evaluated; a flag that has returned the same value for 30 days is a candidate.
- In code, the flag check lives in one place: a selector returns one of two implementations. Removing the flag is then deleting one class, not hunting for 20
ifs.
Static analysis helps too: if flag names are constants, CI compares the list in the flag service with usage in code. A flag that is in code but not in the service is an error, and so is the reverse.
The hardest part is people. I introduced a rule that "removing the flag is part of the feature's definition of done". Without it, new work always turns out to be more important.
Sign up to mark studied questions and save your progress.