Architecture & opsUpdated 2026-11-20

Feature flags

Runtime switches that separate deploying code from releasing it: the four kinds of flag, per-tenant rollout, and flag debt.

Light switches in the back room. Staff turn features on or off in a second.

That is a feature flag. The new feature is already installed. Whether customers see it is a switch someone can flip, with no new delivery truck.

How it works

A flag is a runtime switch that turns behaviour on or off without a deploy. It separates deploying code from releasing it. The code ships dark, and the release is a decision made later.

Code
if flags.isEnabled("new-checkout", { tenantId, plan })
  → new path
else
  → old path

Four kinds of flag

KindPurposeLifetime
ReleaseHide unfinished work, roll out graduallyDays to weeks, then delete
Ops or kill switchTurn off a failing or costly feature fastLong-lived
ExperimentCompare variantsUntil the test ends
PermissionGate features by plan, tenant or roleLong-lived

The kinds behave differently, so they should not share one lifecycle. A release flag that is never removed turns into dead code. A kill switch that is removed during a tidy-up removes the safety it was added for.

Rules for evaluating a flag

  • Evaluate on the server. Pass the result to the client. Do not ship the rules to the browser.
  • Target per tenant. In a multi-tenant product, roll out to internal tenants first, then design partners, then a percentage, then everyone.
  • Default to the safe value. If the flag service is unreachable, the code should fall back to the behaviour that is least likely to hurt.
  • Put kill switches on anything that costs money per call, such as LLM, voice or SMS calls.

Where flags run

A flag can live in a hosted service or in a plain table with a name, a default and per-tenant overrides. A small table is enough for a small team at the start. The hosted tools add targeting rules, percentages and audit trails, which matter once many people change flags.

Rolling out and rolling back

A gradual release moves in steps: internal users, a few design partners, a small percentage, then everyone. At each step, watch error rates and the numbers that matter to the business. If something looks wrong, switching the flag off is a rollback that takes seconds, where a redeploy takes minutes and carries its own risk. This is the main reason release flags exist, and it works best when the old path is still in the code and still tested until the rollout is complete.

Where I used it

I haven't shipped this in a public project yet.

None of my case studies describe a flag system, so I will not claim one. The nearest idea in my work is the sandbox-first fiscal provider in IMS, where an unsupported provider is refused. That is a fail-closed design choice and a different thing from a runtime switch.

Trade-offs

  • Flag debt. Stale flags clutter the code and nobody remembers what they do. Give every release flag an owner and a removal date.
  • More code paths to test. Each flag doubles the combinations in theory. Nested flags that interact are the worst case, and nobody can test them all.
  • Another dependency. A flag service or table is something else to run, and it sits on the request path.
  • Not a replacement for entitlements. What a customer paid for belongs with billing, where plans map to features. Using a flag as a pricing gate hides a business rule in an operations tool.
  • Not for constants. Config that never changes belongs in an environment setting or a constant.

A useful rule: add a flag when you need to release separately from deploying, or switch something off fast. Delete it as soon as that need is over.