Feature flags: combinations, kill switch, cleanup
A feature flag is a configuration switch that turns a feature on or off without a new deploy, so several versions of behaviour live in production at once. Both states are tested (especially off), the transition between them with existing data and the flag value in production, and of the combinations only real and related ones. A kill switch is verified before an incident, and an old flag removed after full release.
Product Engineering · Experiments
The flag was turned off, but a user still has an order from the old path. What happens to it?
The team ships a new checkout behind the new-checkout flag. All is well on the staging stand, and in production the flag is turned on for 10% of Ukrainian users. An hour later the metrics are better, but an error appears: some people who started checkout while the flag was on and finish it after it was turned off get a hanging order. The "flag off" test and the "flag on" test both passed, but nobody tested the transition between states. This lesson is about testing features behind flags: states, transitions, combinations, emergency switch-off and cleanup.
How it works and why. A feature flag is a switch in configuration that turns functionality on or off without a new deploy. They are managed by custom configs or services such as LaunchDarkly or Unleash. Flags separate two moments that used to be one: deploying code and enabling the feature for people. So you can merge unfinished code, open a feature gradually, enable it for part of the users and switch it off quickly if something goes wrong. The price of the flexibility: several versions of behaviour live in production at the same time, and all of them must work.
Flags differ, and the type decides their life and testing. A release flag enables a feature gradually and must disappear after the full rollout. An experiment flag holds an A/B test. An ops flag (kill switch) switches off a risky feature in an emergency. A permission flag opens a feature to certain groups, for example paying users. The first two are temporary by design, the last two can live for years.
How to test a feature behind a flag.
- Both states. Flag off: behaviour as before (no regression); on: the new one. The first is often forgotten;
- Transition. What happens when the flag is turned on and the user already has data created by the old logic? What when it is turned off in the middle of a session, as in the opening example?
- Targeting. The rules (percentage, country, role, app version) work as intended, including on the boundaries and for unauthenticated users;
- Combinations. n flags give 2n states;
- Environments. A flag is configured differently in dev, staging and production. Before a release its value in production is checked, not only the test one.
Example: combinations of two flags. The team has two flags: new-checkout and express-pay, the latter adds a quick-pay button to the new checkout. In theory four states:
| new-checkout | express-pay | What it is |
|---|---|---|
| off | off | Current production. Regression |
| on | off | An intermediate rollout stage |
| on | on | The target state |
| off | on | Invalid: express-pay needs the new checkout |
The three real combinations (those existing in production at different stages) get a full test. The fourth is unreal, so a robustness check is enough for it: if someone configures it wrongly, the app must not break. The expected behaviour: express-pay without the new checkout is silently ignored or explicitly forbidden by configuration validation. The selection principle: take combinations that really coexist in production and pairs of flags that touch the same area of code. This way the 2n do not have to be enumerated.
The team also has discipline in describing a flag. A configuration fragment with an owner and a review date (the structure is illustrative, not the format of a particular service):
{
"key": "new-checkout",
"type": "release",
"owner": "team-payments",
"reviewAfter": "2026-12-15",
"rules": [
{ "country": ["UA"], "percent": 10 }
]
}
Two approaches to a flag after release
Keep the flag "just in case"
A dead code branch and tests for it, plus the risk that someone turns the flag off "to try" and brings the old path back.
An owner and a review date from day one
After the full rollout the old path and the flag are removed. Deliberately long-lived flags have an owner and a purpose.
A kill switch is a flag meant to switch off a risky feature in an emergency (payment through a new provider, a heavy query). It is checked in advance: the switch-off really works fast, without a restart; the app behaves correctly (there is a fallback path or a clear message), does not crash and does not lose data created while the feature was on. A kill switch is worth nothing if nobody has ever used it: the check is done before an incident.
Cleanup. Every flag is temporary complexity. A flag that has long been on for everybody leaves a dead code branch and tests for it, and a trap: someone will switch it off "to try". So when a flag is created an owner and a review date are assigned. After the full rollout the flag and the old path are removed. Deliberately long-lived flags (a kill switch, access to paid features) stay, but also with an owner. Long "forgotten" flags are technical debt that QA should remind about.
Limits and alternatives. A flag does not replace testing on the stand: "off in production" does not mean the code is safe, because imports and migrations still run. Database schema changes behind a flag need compatibility in both directions (see the lesson on safe releases). A separate branch in the repository gives a simpler picture, but long-unmerged code is hard to merge, which is why flags are popular for big changes. In mobile apps a flag does not replace an update: old versions without the new code will never see it, and the flag value is cached.
Common mistakes.
- Checking only the "on" state: nobody sees the regression in the off one.
- Not checking the transition: switching off mid-session or with existing data.
- Testing the flag only in the test environment and not checking its production value before release.
- Creating a flag without an owner and a review date.
- Not checking the kill switch in advance: at the moment of an incident it turns out to require a restart.
- Trying to enumerate all 2n combinations instead of choosing the real and related ones.
Check yourself
You have three flags. How many states are there in theory and how do you decide which to test?
Answer
In theory 2 to the power of 3, that is eight. Test the combinations that really coexist in production at different rollout stages and the pairs of flags that touch the same area of code. Invalid combinations are checked separately, so that a configuration error does not break the app.
A kill switch for a new payment provider was turned off during an incident. What should already have been checked in advance?
Answer
That the switch-off works fast and without a restart, that the app has a fallback path (the old provider) or a clear message, that it does not crash and does not lose orders created while the feature worked. It is checked before an incident, not under its pressure.