What Is a Feature Flag - and When You Actually Don't Need One

A feature flag is a conditional in your running code that decides, at request time, whether a particular code path executes. The point of a feature flag is that the decision lives outside the deployed artifact - you change behaviour by changing a value somewhere else, not by shipping a new build.

That solves one specific problem: in a normal pipeline, deploying code and releasing behaviour are the same event. Merge, build, ship, and the moment the binary is live, users have the new thing. If it's wrong, your only lever is another deploy.

Flags break that coupling. The code goes out dark, and the decision to turn it on becomes a separate, cheap, reversible action - one you can take for 1% of users, or for one internal account, or for everyone, and then undo in seconds.

The cost is that every flag is a branch in your runtime behaviour that someone has to own, test, and eventually delete. That bill is real, and most of this page is about when it is worth paying. Two business professionals brainstorming and planning software development with a whiteboard in an office.

ConceptFeature flag (also feature toggle, feature switch)
Where it sitsApplication layer - a runtime conditional between your config source and your request-handling code
In one sentenceA feature flag lets you deploy code in the off position and decide later, without a new build, whether and for whom it runs.

The 60-Second Answer

A feature flag is a named boolean (or a value) your code reads at runtime to pick between two paths. Both paths are in the deployed binary; the flag decides which one a given request takes.

The problem it solves: deploy and release stop being the same event. You can merge unfinished work behind an off flag, roll a change out to a slice of traffic, and turn it off without a rebuild - so a bad change costs a config change instead of a rollback deploy.

The cost it adds: every flag doubles the behaviour space of the code around it. Two live flags in the same path means four combinations, only one or two of which you actually tested. Flags that outlive their purpose become feature flag technical debt - dead branches nobody dares remove.

Rule of thumb: if you can already deploy safely in minutes and roll back just as fast, you may not need a flag system at all.

How It Actually Works

1. The flag is a read at a decision point, not a build-time switch

Evaluated per request, in process

A feature flag is a lookup followed by a branch, executed while the request is in flight. Both the old and new code paths are compiled into the same artifact; the flag chooses.

This is what distinguishes a flag from a compile-time conditional or a build variant. If flipping the switch requires a rebuild or a restart, you have configuration, not a flag - you have lost the thing that makes flags useful, which is changing behaviour on a running system.

if flags.enabled("new_pricing_engine", user=ctx.user):
    return new_pricing.quote(cart)
return legacy_pricing.quote(cart)

⚠️ In production — Putting the read at the wrong altitude is the common mistake. Read the flag once at the edge of a request and pass the decision down; if you read it at ten different depths of the same call stack, a flip mid-request can give you a half-old, half-new execution that no test covers.


2. The flag value comes from a source the deploy does not own

Config lives outside the artifact

For the decision to be changeable without a deploy, the value has to live somewhere the deploy pipeline doesn't rewrite: a database row, a config service, a key in a store your process polls or subscribes to.

That choice of store is the whole architecture. An environment variable gives you a flag you can only change by restarting - fine for a kill switch you expect to use once, useless for a percentage rollout. A row in your own database gives you a flag you can change with a SQL statement and no new infrastructure.

⚠️ In production — Whatever the source, your process is now reading external state on a hot path. Cache the value in memory with a short refresh, and make sure a failure to reach the source returns a defined default rather than throwing - otherwise your config system becomes a new way for the whole service to go down.


3. The default on failure decides what kind of outage you get

Fail closed or fail open, chosen deliberately

Every flag read needs an answer for "the flag source is unreachable." There are only two answers, and they are not interchangeable.

A flag guarding new, unproven code should fail to off: if you can't reach the config, you run the path that has been in production for a year. A flag that has become the only path - because the old branch was deleted - must fail to on, or an unreachable config service turns into a feature outage. The flag's correct default changes over its lifetime, and nobody updates it.

⚠️ In production — Stale cached values are a third state people forget. A process that started hours ago with a cached "off" and has since lost contact with the config source is serving the off path while your dashboard confidently shows the flag as on. Expose the value each instance is actually using, not the value you set.


4. Targeting turns a boolean into a function of the request

Who gets it, not just whether

Once the flag read takes context - a user ID, an account tier, a region - the flag stops being a global boolean and becomes a rule evaluated per request. That is what enables internal-only testing, beta cohorts, and percentage rollouts.

Percentage rollouts need stable bucketing: hash a stable identifier and compare it to the threshold, so the same user gets the same answer on every request. Bucketing on something that changes per request flickers users between the two paths.

# stable: same user, same bucket, every request
bucket = hash_to_percent(f"new_pricing_engine:{user.id}")
enabled = bucket < rollout_percent

⚠️ In production — Bucketing by user breaks when the thing you changed is shared. If the new path writes a differently-shaped row that the old path then reads, a 10% rollout does not expose 10% of your users to the change - it corrupts shared state for everyone. Flags are clean for behaviour that is local to a request, and dangerous for changes to shared data.


5. The flag lets unfinished code merge to the main branch

Why trunk-based development leans on flags

This is the use that drives most adoption. A large change can be merged in pieces, each piece shipped to production behind an off flag, with the feature only assembled and enabled once all the pieces are in.

The alternative is a long-lived branch that diverges for weeks and then merges in one terrifying commit. Flags trade that integration risk for runtime complexity: the code is always integrated, but production now carries branches that are not yet exercised by real traffic.

⚠️ In production — Code that has only ever run with the flag off has never actually run in production. "It's been deployed for three weeks" is not evidence it works - the off path has been deployed for three weeks. Turn it on for internal traffic early, or the flag is just a long-lived branch with extra steps.


6. Every flag is a tested and an untested combination

Where the complexity compounds

One flag means two paths. Two flags in the same request path mean four combinations. Your test suite almost certainly covers the all-off state and the state you are currently rolling out, which leaves the rest as combinations nobody has ever executed.

The practical defence is scope: keep flags independent, so no flag's correct behaviour depends on another flag's value. When you find yourself reasoning about what happens if flag A is on and flag B is off, that pair is already a bug waiting for the right traffic.

⚠️ In production — Flag interactions surface in exactly the worst place - during an incident, when someone flips a kill switch and hits a combination that was never valid. Keep a short list of which flags are currently live per service; the combinatorial surface only stays manageable if you can see how big it is.


7. Removal is part of the feature, not cleanup you do later

How feature flag technical debt accumulates

A flag has a purpose and therefore an end. When a rollout reaches 100% and stays there, the flag and the losing branch are dead weight: a conditional that always goes one way, plus code nobody runs but everyone must still read and keep compiling.

This is feature flag technical debt, and it compounds quietly. The old path drifts out of sync, its tests rot or get deleted, and six months on nobody knows whether flipping the flag back is a rollback or an outage.

The fix is unglamorous: when you open a flag, write down what condition ends it and who removes it, then treat removal as the last task of the feature rather than a backlog item.

⚠️ In production — The genuinely dangerous flags are the ones treated as a safety net long after the old path stopped working. People keep a stale flag because "we can always turn it off" - a belief that is false, untested, and only gets checked under pressure during an incident.

Minimalist photo of white electrical rocker switches on a textured stone wall background. ## Where You Meet It
  • A payments team rewrites the tax calculation. The new engine ships behind an off flag, runs for a month in shadow mode on internal accounts, then rolls to 1%, 10%, 50% of merchants, with the old engine still compiled in. When a rounding discrepancy shows up at 10%, the flag goes back to 0% in seconds instead of waiting for a rollback deploy to propagate.
  • A mobile app's server adds a new recommendation endpoint. Because app releases go through store review and old versions linger for months, the server-side flag is the only way to turn the feature off for clients already in the wild. Here the flag is not convenience - the client cannot be redeployed on your schedule, so runtime control is the only control you have.
  • An operations team wraps an expensive analytics write in a kill switch. It is not a rollout flag; it is a lever to shed load during an incident. It has one job, it defaults to on, and it is expected to live indefinitely - which makes it a different thing from a release flag even though the mechanism is identical.
  • A B2B platform gates a feature by customer plan. This looks like a flag and is often implemented with the same library, but it is really entitlement logic: permanent, part of the product, driven by contracts. Treating it as a temporary flag means it will show up on your cleanup list forever and never be removed.

When You Actually Need It

  • A deploy or rollback takes long enough that an incident response measured in minutes is unacceptable - flags give you a lever that acts in seconds while the artifact stays put.
  • You have clients you cannot redeploy on demand: mobile apps in app stores, on-premise installs, long-lived SDK versions. Server-side flags are the only remaining control surface.
  • A change is risky in a way tests cannot settle - a rewritten calculation, a new data source, a different cache strategy - and you need real production traffic in graduated slices to find out.
  • A multi-week change needs to merge to main in pieces to avoid a divergent long-lived branch, and the partial state must be inert in production until it is complete.
  • You need a deliberate kill switch for an expensive or non-critical subsystem so you can shed load during an incident without deploying anything.
  • Release timing is a business decision owned by someone who is not on call - a launch date, a contract start - and you want that decision not to require an engineer and a deploy.

When You Don't

  • Your deploys are already fast and safe. If you can ship or roll back in a couple of minutes with an automated pipeline, a deploy is your flag flip. A small service with one or two engineers and a short pipeline should just deploy; adding a flag system buys you a config store, a cache, a failure mode, and a cleanup backlog in exchange for shaving a minute.
  • The change is small and reversible. Copy edits, a tweaked validation rule, a renamed field - wrap these in a flag and you get two code paths to maintain for a change you would never roll back anyway. Ship it. Keep flags for changes whose blast radius you cannot predict from the diff.
  • It's really a permanent product decision. Plan tiers, per-tenant entitlements, regional legal rules, user preferences - these are features, not flags. They belong in your data model as entitlements or settings, where they can be queried, audited, and billed against. Named booleans in a flag dashboard rot there forever because nobody can tell them apart from stale rollout flags.
  • The change touches shared state or a schema. A percentage rollout where the new path writes data the old path must read is not a partial rollout - it's both code paths operating on one inconsistent store. Use the standard migration sequence instead: additive schema change, dual write, backfill, read switch, drop. A flag may gate the read switch at the end, but it cannot make an incompatible migration safe.
  • You cannot name the condition that removes it. If there's no answer to "what has to be true for this flag to go away, and who deletes it," you are not adding a flag - you are adding feature flag technical debt with a nicer name. A branch that will never be removed is better off as a plain config value, documented as permanent.
  • You'd reach for a vendor platform before you have the problem. The first few flags are a config table and a cached read of it, maybe a hundred lines. Targeting rules, audit logs, approval workflows, and SDKs for six languages solve problems of scale and organisation. Adopt that when the number of flags and the number of people touching them make it hurt, not on day one. Person analyzing financial data on screens, making notes. Ideal for business and finance themes.

What People Get Wrong

"Feature flags let us deploy safely without a staging environment or good tests."

A flag limits the blast radius of a bad change; it doesn't tell you the change is bad. You still need the observability to notice the 5% cohort is failing, and you still need tests for both paths. A flag is a faster undo, not a substitute for knowing whether to undo.

"A flag is a rollback - we can always just turn it off."

Only while the off path still works. Once the new path has written data in a new shape, or the old branch has drifted without tests, flipping back is an untested code change executed under incident pressure. The flag is a real rollback only if someone keeps exercising the off path.

"Flags are free - it's just an if statement."

The conditional is free; the branch it creates is not. Each live flag multiplies the behaviour space, needs an owner and a removal condition, and adds a runtime dependency on a config source. The cost shows up months later as combinations nobody tested and code nobody will delete.

"We need a feature flag platform to do this properly."

A platform earns its place when flag count and the number of people flipping them make governance the hard part - audit trails, approvals, consistent targeting across services. Before that, a config table plus a cached read gives you the actual mechanism, and you'll understand your own failure modes better for having built it.

Why It Was Built This Way

Flags exist because of a constraint in how software reaches users: the unit of deployment is much larger than the unit of change. You don't ship one function; you ship a binary, an image, a bundle. Every change inside that unit goes live at the same instant, to everyone, as one atomic event.

For a long time, the answer was to make the unit less frequent and more carefully inspected - release trains, freeze windows, long QA cycles. That reduces how often you take the risk without reducing the risk of any single release, and it makes each release bigger, which makes the risk worse. The alternative answer is to keep shipping often but stop letting deployment mean release. That requires a decision point inside the running system, which is exactly what a flag is.

What was traded away is determinism about what your production code does. Before flags, the deployed artifact plus its environment told you the behaviour; a commit hash was a complete description of production. With flags, the artifact describes the space of possible behaviours, and the actual behaviour is the artifact plus current flag state plus which instance cached what plus which bucket the user hashed into. That is why debugging flagged systems means asking "what flags were on for that request?" before anything else, and why mature setups log flag evaluations alongside the request.

The second thing traded away is the ability to delete code confidently. A flag is a promise that both branches still work, and that promise is almost never re-verified. The industry calls the result feature flag technical debt, but the underlying mechanism is simpler than the name suggests: you bought flexibility with a loan against future cleanup, and the interest is paid by whoever has to reason about the code next.

Related Briefs

What to Read Next

  • trunk based development vs feature branches
  • canary deployment vs blue green deployment
  • database migration with zero downtime

A feature flag is worth it when the cost of being wrong in production is higher than the cost of maintaining a second code path - rewritten business logic, clients you can't redeploy, changes whose blast radius you can't predict from the diff. Below that bar, a fast pipeline and a boring deploy are the better tool. If you do add one, decide at the same moment what ends it and who removes it; a flag without an exit condition is a permanent branch you have agreed to maintain without admitting it.

댓글

이 블로그의 인기 게시물

What Is a Message Queue - and When You Actually Don't Need One

What Is a Bloom Filter - and When You Actually Don't Need One

When to Use GraphQL Over REST API - and When REST Is Still the Right Call