← writing
6 April 2022

Four feature flags, and how long they live

A classification that is not mine, and the question it leaves open: when the flag goes away. Without a written answer, it ends up as part of the product.

This site’s mark is a switch, which calls for some rigour on the subject. Martin Fowler sorted feature flags (the term used there is feature toggles) into four families. The classification is Fowler’s; I use it because it leads to a question it only mentions in passing, the lifetime of a flag.

01The four families
  • Release flag: it hides unfinished code in a version already released. It must be removed when development ends.
  • Experiment flag: it sends two populations down two paths to compare them. It must be removed when the measurement ends, and that duration is set in advance.
  • Ops flag: it switches off an expensive feature when the system is overloaded. It stays as long as the system does.
  • Permission flag: it opens a feature to certain accounts. It stays as long as the product, because it is in fact a business rule.

The list runs from the most short-lived to the most permanent. The first two families must disappear, the last two are meant to stay. The common mistake is to confuse the two halves, always in the same direction: a temporary flag is treated as permanent.

02What a surviving flag costs

Each flag doubles the number of possible paths through the code, and two flags multiply it by four. The condition itself costs only three lines. The cost comes from the combinations that stop being tested. A release flag forgotten after release leaves a path nobody uses, nobody tests, and nobody dares remove because nobody knows what it was for.

03The rule I apply

Every flag in the first two families is created with a removal date written in the code itself, not in a ticket that eventually gets closed. On that date it is removed, or its extension is justified in writing. The constraint is tedious, but it is the only one I have seen respected for more than a quarter.

04Flag management tools

This article does not cover tooling: the services that control flags remotely, their dashboards, their pricing. They handle distributing a setting, not removing it, and removal is where the problem lies. On a system maintained by one person, a configuration file and a date are enough.