Skip to content

    System Design

    Feature Flags: Releasing Without Deploying

    Learn how feature flags separate deploying from releasing: flag types, sticky percentage rollouts, kill switches, safe defaults and the cost of leftover flags.

    By Published 9 min read

    Share

    Focused lessonintermediateBackend System Design

    Before this: Deployment Strategies: Blue-Green, Canary and Rolling

    What you'll learn: By the end of this lesson you will be able to explain how a flag separates deploying code from releasing it, name the four common kinds of flag and how long each lives, describe how a sticky percentage rollout is computed from a stable key, choose a safe default for when the flag source is unreachable, and say what leftover flags cost.

    A building has a fuse box. The wiring for a new room is installed while the breaker is off; nobody gets power until someone flips it, and if something sparks, flipping it back is the whole repair. A feature flag is that breaker for a piece of code: the code ships switched off, and a separate decision turns it on.

    This lesson builds on deployment strategies, which decide which servers run the new build. A flag decides which requests take the new code path inside a build already running everywhere.

    Verified on 2026-12-01 against Martin Fowler's article on feature toggles, the OpenFeature documentation on the evaluation context, and the Unleash documentation on gradual rollout and stickiness. No flag service was available: the one script below was run with Node and its output is shown.

    The core idea

    A flag is a conditional in the code whose answer is decided outside the code. Because the answer can change while the service keeps running, "deploy" (the build is on the servers) and "release" (users get the behaviour) become two separate events with two separate owners and two separate rollbacks.

    Three illustrations run through the lesson:

    • Minimal example: a sticky 5% rollout computed from a hash.
    • Realistic example: ShopStream releases a new courier-assignment rule behind a flag.
    • Failure example: the flag source is unreachable and the default is wrong.

    Four kinds of flag

    Fowler's article sorts flags by how long they live and how dynamic the decision is:

    Kind Purpose Lifetime and dynamism, per the article
    Release toggle Ship unfinished code dark, then enable it Transitionary, usually not more than a week or two; mostly static decisions
    Experiment toggle A/B and multivariate tests Decided per request; must stay stable long enough for significant results
    Ops toggle Control operational behaviour, including a kill switch Mostly short-lived; some long-lived kill switches act as manual circuit breakers
    Permissioning toggle Features for certain users or plans Per request; may live for years

    Treating them as one thing causes most flag trouble: a release flag never removed becomes a permanent branch, and a kill switch removed after launch takes away the fastest way to stop an incident.

    How a flag is evaluated

    Fowler names the parts: a toggle router decides which code path is live, toggle configuration supplies the settings it uses, and a toggle context (a user identity, a cookie) enables per-request decisions. OpenFeature uses the same shape: the evaluation context is "a container for arbitrary contextual data that can be used as a basis for dynamic evaluation", and its optional targeting key identifies the subject of the evaluation and is used for deterministic percentage-based rollouts. The documentation says the key should "contain a string uniquely identifying the subject", such as a UUID.

    Flag evaluation inside a serviceRequest to Service code; Service code to Flag client (evaluate); Flag source to Flag client (rule updates)Request: user id, planRequestuser id, planService code: if flag onService codeif flag onFlag client: local rulesFlag clientlocal rulesFlag source: rules, targetsFlag sourcerules, targetsevaluaterule updates

    Figure 1. Where a flag decision is made. How to read this: the request supplies the context, the code asks the flag client, and the client answers from rules it already holds. The flag source updates those rules in the background, so the request path does not wait on it.

    A sticky percentage rollout

    A rollout to 5% of users must give a user the same answer every time, or the feature flickers. Unleash states the goal as guaranteeing "that the same user gets the same features every time", and describes hashing a context field with the strategy's group id into a number from 0 to 100; it checks userId first and then sessionId, and if neither exists it falls back to a random number, so "stickiness is not guaranteed". Its gradual rollout uses a normalized MurmurHash of the user's ID.

    Minimal example (illustrative). This script uses SHA-256 rather than MurmurHash, but the principle is the same: hash the flag key together with the user id, take a bucket from 0 to 9,999, and compare it with the percentage.

    import { createHash } from "node:crypto";
    function bucket(flagKey, userId) {
      const h = createHash("sha256").update(`${flagKey}:${userId}`).digest();
      return h.readUInt32BE(0) % 10000;
    }
    function isOn(flag, userId) {
      if (!flag.enabled) return false;
      return bucket(flag.key, userId) < flag.percent * 100;
    }

    Run with Node v26.13.1 over 10,000 synthetic user ids (user-0 to user-9999), it printed:

    on at 5%: 506
    on at 25%: 2458
    5% subset of 25%: true
    same user twice: true
    overlap with another 5% flag: 27
    kill switch off: 0

    Four properties are visible. The share is near the target, not on it. The 5% group is entirely inside the 25% group, so raising the percentage only adds users. The same user gets the same answer. And because the flag key is part of the hash, two flags select different groups: the overlap with an unrelated 5% flag was 27 users, close to the 25 an independent split would give. Setting enabled to false turned the feature off for everyone, which is the kill-switch behaviour.

    flowchart TD accTitle: Order of a flag evaluation accDescr: A flag check first asks whether the flag is enabled. If not, the old path runs. If it is, specific targets such as internal users are checked, then the percentage bucket from a stable key. A failure to evaluate returns the configured default. S["Request reaches the flag check"] --> E{"Flag enabled?"} E -->|no| OFF["Old code path"] E -->|yes| T{"Targeted user or group?"} T -->|yes| ON["New code path"] T -->|no| P{"Stable-key bucket
    below the percentage?"} P -->|yes| ON P -->|no| OFF S -.->|evaluation fails| D["Return the default value"]

    Figure 2. One evaluation. How to read this: the switch is checked first so a kill takes effect for everyone; targets and the percentage decide the rest. The dashed line is the case people forget: what happens when the flag cannot be evaluated at all.

    Flags and deployment strategies together

    A canary decides which pods run version 2; a flag decides which requests use the new behaviour inside it. Together: deploy everywhere with the flag off, confirm health, then raise the flag in steps. A bad behaviour is rolled back by a flag change; a bug in code that runs regardless of the flag still needs a deployment rollback.

    stateDiagram-v2 accTitle: Life of a release flag accDescr: A release flag is created off, deployed, enabled for internal users, raised in percentage steps, fully on, then removed from the code. A problem at any enabled stage returns it to off. A flag that skips removal becomes permanent clutter. [*] --> Off: created, code deployed dark Off --> Internal: enable for staff Internal --> Partial: raise percentage Partial --> FullOn: all users Partial --> Off: problem, switch off Internal --> Off: problem, switch off FullOn --> Removed: delete flag and old path Removed --> [*]

    Figure 3. A release flag's lifecycle. How to read this: the last step is the one that gets skipped. A flag at "full on" with its old code path still present is already a cost.

    What flags cost

    Fowler calls toggles "inventory which comes with a carrying cost": each adds a conditional, an abstraction and testing burden. To keep it down he suggests a removal task created with every release flag, expiration dates, "time bombs" that fail a test after expiry, and a cap on the number of flags. He says it is not necessary to test every combination: test the expected production configuration, the fallback with new toggles off, and sometimes all on.

    Choice Gain Cost Wrong when
    Flag in code, rules in the source Instant change, per-user control Conditionals, a dependency on the flag source The change is permanent and trivial
    Dynamic rules in a flag service Fast, targeted, auditable Another system to run and secure A single global switch is enough

    Build it

    There is no lab for this lesson. No flag service was available, so the only code that ran is the bucketing script above.

    In practice: ShopStream releases a new courier-assignment rule

    This is an educational scenario with illustrative numbers.

    This is a realistic scenario, not a case history.

    The situation

    This is the realistic example. ShopStream assigns each order to a courier. A new rule weighs distance and load differently and cannot be tested well offline.

    Starting architecture

    The assignment service reads orders from a queue and picks a courier with the current rule. The new rule is in the same build behind a release flag, assign-v2, off by default.

    Options considered

    Option Gain Cost Wrong when
    A. Deploy and enable together Simple Any bug reaches everyone The rule changes money or safety
    B. Flag with a percentage rollout Small exposure, instant undo Flag source and cleanup work The two rules cannot coexist on one queue

    The decision

    Option B, preceded by a shadow run in which the new rule's choices are logged but not acted on, and only then enabled for 5% of orders. The targeting key is the order id, not the courier, so one order always takes one path. A kill switch flag, assign-kill, is a separate ops flag that forces the old rule and is never removed.

    Rollout and verification

    Raise the percentage in steps with a pause at each, comparing assignment delay and reassignments for the flagged group against the rest, as in a canary. Once 100% has held through a normal peak, delete assign-v2 and the old path.

    The 2 a.m. failure

    The page reads: "Assignments stalled in one region". The flag source was unreachable after a network change, and the flag client could not evaluate assign-kill. Its configured default was the new path, not the old one, so a request that should have been forced to the old rule took the new one.

    sequenceDiagram accTitle: A kill switch that cannot be evaluated accDescr: The assignment service asks the flag client whether the kill switch is on. The flag client cannot reach the flag source and returns its configured default, which is the new path, so the request takes the new rule although the kill switch was turned on at the source. participant A as Assignment service participant C as Flag client participant S as Flag source Note over S: assign-kill turned on C--xS: cannot connect A->>C: is assign-kill on? C-->>A: default value, new path Note over A: the old rule is not used

    Figure 4. A default that undoes the switch. How to read this: the switch was flipped at the source, but the client never heard, and its default chose the risky path.

    First checks: the flag client's connection state and which default each flag returns. Mitigation: restore access to the source, or ship a configuration that changes the default. Follow-up: the default for an unreachable flag must be the safe path for that flag: off for a release flag, and for a kill switch the state that keeps the system conservative. Test that failure on purpose.

    Architect's notes

    • Name the kind of flag when you create it, with an owner and, for release flags, a removal date.
    • Use a stable targeting key matching the unit you care about: user, order or tenant.
    • Keep a tested kill switch for every risky new path, and log which variant served each request.
    • Do not let flags guard schema changes. A flag cannot undo data already written.

    Common mistakes

    • Never deleting release flags.
    • Targeting with a random value, so users flip between variants.
    • A default that is the risky path when the flag source is down.
    • Nested flags whose combinations nobody has tested.

    Key takeaways

    • A flag separates deploying code from releasing it, and gives it its own rollback.
    • Release, experiment, ops and permissioning flags live for different times.
    • A sticky percentage rollout hashes a stable key with the flag key, so raising the percentage only adds users.
    • The default when a flag cannot be evaluated is a design decision, not an afterthought.
    • Every flag is carried inventory: remove release flags, keep and test kill switches.

    Practice exercises

    Exercise 1 (20 min). Adapt the script to take a userId list and print which users enter when the percentage goes from 5 to 10. Confirm none leave.

    Exercise 2 (30 min). For ShopStream, list four flags (one of each kind) with owner, default if the source is unreachable, and removal date.

    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