Skip to content

    Frontend System Design

    Feature Flag Lifecycle and Experiment Pitfalls

    Keep flags from becoming debt and experiments from lying: a flag's lifecycle, safe removal order, sample ratio mismatch, peeking, exposure and cache traps.

    By Published 13 min read

    Share

    Standard lessonadvancedFrontend System Design

    Before this: Feature Flags and A/B Testing

    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

    1. 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.
    2. 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.
    3. 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

    stateDiagram-v2 accTitle: Life of a feature flag accDescr: A flag is defined with an owner and an end date, then developed behind the off variant, then released to production by rules and ramps. When a decision is made it moves to cleanup, where the code for the losing path and the flag calls are deleted. Only after the code has shipped and old bundles have aged out is the flag configuration archived. A flag past its end date without a decision is stale and returns to a review. [*] --> Defined Defined --> Developing: owner and end date set Developing --> InProduction: rules and ramp InProduction --> Decided: result read, winner chosen Decided --> Cleanup: delete losing path and flag calls Cleanup --> Archived: code shipped, old bundles aged out Archived --> [*] InProduction --> Stale: end date passed, no decision Stale --> Decided: review

    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

    sequenceDiagram accTitle: Order of removing a feature flag accDescr: The team decides the winner and ships a release that makes the winning path unconditional and deletes the flag calls. An old tab still runs the previous bundle and keeps evaluating the flag, so the flag configuration stays. Once old bundles have aged out, the team deletes the flag configuration. If the configuration is deleted before the old bundles are gone, the old tab evaluates a missing flag and gets its fallback. participant T as Team participant R as Release participant O as Old tab (old bundle) participant F as Flag service T->>R: ship winner, delete flag calls O->>F: still evaluates the flag F-->>O: answer from current config Note over O,F: keep the flag configuration for now T->>T: wait for old bundles to age out T->>F: delete the flag configuration Note over O,F: too early: FLAG_NOT_FOUND, fallback served

    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?

    flowchart TD accTitle: Checklist for deleting a feature flag accDescr: Ask whether a decision has been made. If not, make it or extend the end date with a reason. If yes, ask whether the winning path is now unconditional and the losing path deleted. If not, do that first. If yes, ask whether any bundle still in use reads the flag. If so, wait. If not, delete the configuration and record the result. A{"Decision made
    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

    An experiment's measurement chain: assignment, exposure, logging and analysis, each with its own checkAssignment to Exposure (variant); Exposure to Event log (events); Event log to Analysis (counts)Assignment: salt and keyAssignmentsalt and keyExposure: shown, onceExposureshown, onceEvent log: joins, filtersEvent logjoins, filtersAnalysis: check split firstAnalysischeck split firstvarianteventscounts

    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

    NOTE

    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

    Starting architecture: flag calls spread through the code, a flag service with several old flags and no owner or end dateStorefront to Flag service (evaluate); Flag service to Dashboard (results)Storefront: flag callsStorefrontflag callsFlag service: old flags, no ownerFlag serviceold flags, noownerDashboard: live winner displayDashboardlive winnerdisplayevaluateresults

    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

    1. Fill the register from the flag service and the code, and mark each flag's kind and decision.
    2. Check before deleting: the split of each finished test passed its sample ratio check, and the decision is written down.
    3. Ship the code removal and watch evaluation errors.
    4. 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?

    In this course:

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments