
What it makes possible
- Turning something off in seconds when it misbehaves, instead of rolling back a release.
- Releasing to a few users first: staff, then one percent, then everyone.
- Merging unfinished work safely, hidden behind a switch that is off.
- Different behavior per customer or plan.
What it looks like
if (flags.isOn("retry-failed-payments", { user })) {
await retryWithBackoff(job);
} else {
await markFailed(job);
}Four kinds, with different lifetimes
| Kind | Purpose | Should live for |
|---|---|---|
| Release flag | Hide unfinished work, roll out gradually | Days or weeks |
| Kill switch | Turn off a risky part in an emergency | As long as the risk exists |
| Experiment | Compare two versions | Until the result is in |
| Plan or permission flag | Give a feature to some customers | Permanently |
The cost
Every flag doubles the number of ways that piece of code can run. Ten flags is about a thousand combinations, and nobody tests a thousand combinations. Flags that are fully rolled out and never removed are one of the most common kinds of clutter in a codebase.
- Give every release flag an owner and a removal date.
- Remove the flag and the dead branch once the rollout is finished.
- Keep the list of flags somewhere people can read it.
Questions you will hear in a meeting
- Is this behind a flag, and who can flip it?
- What is the default if the flag service cannot be reached?
- When does this flag get removed?
- Did we test it with the flag off as well?
In an interview
When asked how you would release something risky, a flag with a gradual rollout and a way to turn it off is the expected answer. Add how you would know that it is going wrong, and you have covered the whole question.