What you'll learn: By the end of this lesson you will be able to describe the stages of a feature flag's life and give each flag an owner and an end date, remove a flag in the order that does not break open browser tabs, explain why reusing a flag name is dangerous, name the common ways an A/B test goes wrong (a sample ratio mismatch, peeking, counting assignments instead of exposures, caches and late swaps, pooled data) and say which check catches each.
Think of the sticky notes on a monitor. Each one made sense on the day you wrote it. A month later some are obsolete and nobody dares throw one away. A feature flag is a sticky note stuck onto your code: cheap to add, and it keeps costing attention until someone removes it. An experiment is a different kind of risk: a thermometer that can read the wrong temperature without any sign that it is wrong.
This lesson continues the previous one on feature flags and A/B testing (read it first for evaluation, bucketing and the lab). The running example is the same shop. All numbers are illustrative.
The core idea
- A flag is a loan. It buys flexibility now and charges carrying cost until it is removed, so every flag needs an owner, a purpose and an end date from the day it is created.
- Removal is a change with an order. Browsers keep old code alive in open tabs and caches, so the flag's configuration must outlive the last code that reads it.
- Experiments fail quietly. A broken split, an early stop or the wrong denominator produces a confident, wrong number. The defence is a short list of checks run before anyone reads the result.
Three illustrations: a minimal example (a flag register with four fields), a realistic example (a three-week shipping-banner test and its cleanup) and a failure example (a split that stops matching its configuration).
The life of a flag
Fowler's feature-toggle article says savvy teams treat toggles as inventory that carries a cost, and it is explicit that release toggles should be short-lived (a week or two, longer if product-led), that ops toggles are mostly short-lived with some long-lived kill switches, and that permission toggles can live for years. Unleash, a flag product, models the same thing as five stages: define, develop, production, cleanup, archived, and says the production stage "serves as a reminder to start cleaning up". It also gives each flag type an expected lifetime and marks a flag potentially stale once it passes it. Its default lifetimes are one vendor's settings, not a standard: 40 days for release and experiment flags, 7 for operational, 90 for sunset flags, and permanent for kill switches and permission flags.
Figure 1. The life of a release or experiment flag
How to read this: the loop that matters is the one from "in production" to "stale" and back. A flag that nobody decides about drifts there. Archiving comes last, after the code has gone.
The smallest useful control is a flag register: one line per flag with its key, kind, owner and end date, and the fallback it must use at the call site. This is the minimal example. It is a convention, not a library, and it works as a check: Fowler mentions teams that give flags expiration dates, that write "time bomb" tests which fail or refuse to start once a flag has expired, and that cap the number of flags so one must be removed before another is added.
Flags also multiply states. Ten independent on/off flags can be in 1,024 combinations (plain arithmetic), and nobody tests all of them. Fowler's advice is calmer: most flags do not interact, so test the configuration you expect to go live and the fallback where the new flags are off, and treat flags that do interact as a design smell.
Removing a flag without breaking open tabs
Deleting a flag has two halves: the code that reads it and the configuration that defines it. A single-page app makes the order important. A tab opened yesterday still runs yesterday's bundle, which still calls the flag. If the configuration is deleted first, that tab's evaluations hit "flag not found". OpenFeature defines that error code as "The flag could not be found", and says an evaluation must return the default value on abnormal execution. So the tab quietly falls back to whatever its call site chose.
Figure 2. Safe removal order
How to read this: code first, configuration last. How long "aged out" takes depends on how your app updates open tabs and caches; measure it rather than guess it.
Figure 3. Can this flag be deleted?
and recorded?"} -->|"no"| A1["Decide, or extend the
end date with a reason"] A -->|"yes"| B{"Winning path now
unconditional?"} B -->|"no"| B1["Make it unconditional,
delete the losing path"] B -->|"yes"| C{"Does a bundle still
in use read the flag?"} C -->|"yes"| C1["Wait"] C -->|"no"| D["Delete the configuration,
archive, record the result"]
How to read this: three questions, in this order. Skipping the middle one leaves dead code that can still be reached.
Never reuse a flag. The SEC's 2013 order against Knight Capital describes what dead code plus a reused flag can do. New code in an order router "repurposed a flag that was formerly used to activate" old code, called Power Peg, that Knight had stopped using many years earlier but which was still present. One of eight servers did not get the new code. On August 1, 2012, orders carrying the repurposed flag reached that server, which ran the old code; in about 45 minutes the firm assumed large unwanted positions and lost more than $460 million, according to the order. It was a trading system, and a missed server and missing review also played a part. The narrow lesson: a repurposed name can wake old behaviour in anything that still reads it, such as a tab on an old bundle.
How experiments go wrong
An experiment depends on a chain: assignment, exposure, logging, analysis. Each link has its own way to fail.
Figure 4. Where an experiment's numbers can go wrong
How to read this: a problem in any box shows up as a wrong count at the end. The split check at the right is what tells you something upstream is wrong.
A sample ratio mismatch (SRM). Microsoft's experimentation team describes an SRM as a statistically significant difference between the ratio of users counted per variant and the ratio that was configured, found with a test such as chi-square rather than by eyeballing the ratio. Their platform uses a p-value below 0.0005. The article lists causes from every stage: faulty bucketing, redirects in one arm, incorrect joins, biased analysis conditions, uneven ramp-up, and, in its worked example, a bot filter that removed highly engaged users in one arm. An SRM is a symptom, and a result with one should not be read until the cause is found. In the lab, section 7 shows it: the assigned counts (5,077 and 4,923) are within chance, while the exposed counts (5,077 and 4,326) fail the check, because part of one arm never logged an exposure.
Peeking. Evan Miller's write-up of the problem says repeated significance testing increases the rate of false positives: peek ten times at an ongoing experiment, and what you think is 1% significance is actually about 5%. His remedy is to decide the sample size before the test and not to test significance repeatedly. A live "winner" dashboard invites it.
Counting the wrong people. Assignment counts everyone evaluated; exposure counts those who saw the change. Analysing assignments dilutes the effect with people who never reached the feature, and mixing the two between arms can create an SRM by itself. The abstract of Microsoft's "Seven Pitfalls" paper adds two more: robots, which are a problem unique to online settings, and Simpson's paradox, where pooled data can point to the wrong winner. When the mix of users differs between arms or over time, which happens when the allocation changed mid-test, compare like with like (the same period, the same segment) before trusting a pooled number.
Caches and late swaps. A page that evaluates in the browser may show the old version first and then swap. web.dev notes that client-side tests often hide page content until the experiment has loaded, which skews the metrics being measured. On the server, a cache that ignores the variant will serve one arm's HTML to the other; the HTTP Vary header exists so caches store separate responses by the request headers listed (MDN), and whichever key you use must include the variant.
Shared salts and key changes. Two experiments with the same salt are not independent (lab section 5 of the previous lesson: every user lands in the same arm of both). A targeting key that changes when someone signs in, or an anonymous id that is lost with cleared storage, re-buckets the person and can move them to the other arm mid-test; decide which key the experiment uses and what you do with people whose key changed.
| Pitfall | Symptom | Check | Fix |
|---|---|---|---|
| Sample ratio mismatch | Arm sizes differ from the configured split by more than chance | Chi-square on exposed counts per arm | Find the cause before reading results |
| Peeking | A winner appears early and fades | Was the sample size fixed beforehand? | Fix the sample size, wait, read once |
| Assignment, not exposure | A small effect, or arms of unequal sizes | Which events does the analysis count? | Count first exposures per key |
| Robots and filters | Odd behaviour in one arm | Compare bot filtering across arms | Apply the same filter to both arms, then re-check the split |
| Pooled data | The pooled winner differs from each segment | Compare by period and segment | Analyse like with like |
| Cache or late swap | Metrics move in both arms | Is the variant in the cache key? Is content hidden? | Evaluate on the server and key the cache |
| Shared salt | Two results move together | Cross-tabulate the two arms | One salt per flag |
Build it
This lesson has no new lab. The pitfalls above are demonstrated by the lab from the previous lesson, examples/frontend/labs/feature-flag-bucketing (a pure model, not a flag vendor; see that lesson for how to run it): section 5 puts two experiments on one salt, section 4 shows the arms staying put when allocation grows, and section 7 runs the sample ratio check. The part of section 7 that matters here is the contrast between assigned and exposed counts:
Expected output, captured from a real run (the end of the demo's output, Node 26.13.1, 2026-12-01):
=== 7. Sample ratio check: assignment is fair, but exposure is not
assigned: control 5077, treatment 4923, chi-square 2.37, p 1.24e-1 -> ok
exposed : control 5077, treatment 4326, chi-square 59.98, p 9.58e-15 -> MISMATCH
In the lab, 12% of the treatment arm "crashes before logging". That mechanism is made up to show the check firing; it says nothing about how often real pages fail.
In practice: a shipping banner test and its cleanup
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
For three weeks the shop ran a 50/50 test of a free-shipping progress banner on the cart. The analysis showed the banner arm ahead, the team shipped it to everyone, and then moved on. Months later, the repository has the flag, both code paths, and four other flags nobody remembers. A cleanup week is planned.
Starting architecture
Figure 5. Starting point: flags with no register
How to read this: nothing links a flag to an owner, an end date or the code that reads it, so nobody can say which flags are safe to delete.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Delete the flag configuration now | The service list is short again | Nothing in code changes | Open tabs on old bundles hit a missing flag and use their fallback |
| Remove the code, then the configuration after old bundles age out | Dead paths vanish, and nothing live reads a missing flag | A second step later | Someone must remember the second step |
| Leave the flags and add comments | No work now | Carrying cost keeps growing | Repurposing a name later |
The decision
| Field | Decision record |
|---|---|
| Context | Four flags are decided or abandoned, one test is finished, and there is no owner or end date for any of them. |
| Decision | Add a register (key, kind, owner, end date, fallback). For each decided flag, ship a release that makes the winner unconditional and deletes the calls, then delete the configuration after old bundles have aged out. Never reuse a key. |
| Consequences, good | Dead code goes, and no live bundle reads a missing flag. |
| Consequences, bad | Two steps per flag, and the second needs a reminder. |
| Revisit when | The number of flags grows again, or a flag needs to outlive its end date on purpose (move it to a permanent kind). |
Rollout and verification
- Fill the register from the flag service and the code, and mark each flag's kind and decision.
- Check before deleting: the split of each finished test passed its sample ratio check, and the decision is written down.
- Ship the code removal and watch evaluation errors.
- Delete the configuration after old bundles have aged out, keeping an archive of the rules.
The 2 a.m. failure
A tidy-up deletes the banner flag's configuration on the day of the release that removes the code. Support reports that some customers see the old cart banner, with a shipping message that disagrees with the total (illustrative). They kept a tab open since yesterday. Their old bundle still evaluates the deleted flag, gets FLAG_NOT_FOUND and uses its call-site fallback, which is the old banner.
First three checks: (1) look at evaluation errors by app version: FLAG_NOT_FOUND from old versions only points at the order of removal; (2) compare the cart code's version in the affected sessions; (3) confirm the flag's configuration was deleted. Mitigation: restore the flag configuration with the final rules (the archive), and let old bundles age out. Follow-up: put "delete configuration" in the checklist as the last step with a date, and alert on FLAG_NOT_FOUND counts.
Architect's notes
- Every flag gets an owner and an end date on creation. Without them nobody can delete it with confidence.
- Delete code first and configuration last, and keep the old rules in an archive.
- Never reuse a flag key. Treat keys as spent.
- Run the sample ratio check first, then read the result once at the planned sample size.
Common mistakes
- Deleting configuration with the code, in one release.
- Reusing an old flag name for a new meaning.
- Analysing assignments instead of exposures.
- Caching HTML without the variant in the key.
Key takeaways
- A flag is inventory with a carrying cost: give it an owner, a kind and an end date, and remove it.
- Remove the code first, the configuration last, and never reuse a key; dead code and a repurposed flag are how old behaviour wakes up.
- An SRM means the split is wrong; find the cause before reading any result.
- Do not peek: fix the sample size before the test.
- Count exposures, and compare like with like when the mix of users changes.
- Key the cache by variant and avoid hiding content while a client-side test loads.
Practice exercises
Exercise 1 — Starter (45 min): Write a flag register for five flags you know, with owner, kind, end date and fallback. Mark which are past their end date.
Exercise 2 — Intermediate (2 hours): In the previous lesson's lab, add a test that fails when a flag's offVariant is not its call-site fallback, then use validateFlag to check one definition against it.
Exercise 3 — Advanced (half day): In that lab, change the demo so that 12% of the control arm also fails to log. Run the sample ratio check and explain why it passes, and what could still be wrong with the data. What second check would you add?
Related reading
In this course:
- Debugging Hydration Mismatches, when two evaluations of one flag disagree.
- CDN and Edge Caching, the cache key that must include the variant.
- Service Worker Lifecycle and Updates, how old code stays alive after a release.
- Real User Monitoring, where exposure and outcome events come from.
Official documentation
- Martin Fowler: Feature Toggles, categories, lifetimes, inventory cost, expiry and testing combinations.
- Unleash: feature flags, flag types, expected lifetimes and stale flags.
- OpenFeature specification: types and flag evaluation, error codes and the default value.
- SEC order, Knight Capital Americas LLC (2013), the repurposed flag and the old code.
- Microsoft Research: Diagnosing sample ratio mismatch in A/B testing, Seven Pitfalls to Avoid when Running Controlled Experiments on the Web and Evan Miller: How Not To Run an A/B Test.
- web.dev: Relating site speed and business metrics and MDN: Vary.