What are feature flags?

A feature flag (or feature toggle) is a runtime switch that turns a piece of code on or off for some or all users without a new deployment. It separates deploying code from releasing a feature.

Also called feature flag, feature toggle, feature flagging, feature switch, kill switchUpdated

Without feature flags, merging code means releasing it. Teams then keep big changes on long-lived branches, merge them late and ship everything at once. A feature flag is an if statement whose condition lives outside the code. The new checkout can be merged and deployed today but stay switched off until product decides to turn it on, first for staff, then for 10% of users, then for everyone.

Types of flag

Pete Hodgson's article on martinfowler.com sorts toggles by how long they live and who changes them. The categories are still the clearest way to think about it:

  • Release flags hide unfinished or untested work. They should live for days or weeks and then be deleted.
  • Experiment flags split users between variants for A/B tests.
  • Ops flags (kill switches) let on-call staff turn off an expensive or failing feature during an incident, such as recommendations on a sale day.
  • Permission flags turn features on for a plan, a tenant or a beta group. These can be permanent.

Mixing them up causes trouble. A release flag that becomes a permanent setting is technical debt with a misleading name.

How a flag system works

  1. Flags and their targeting rules are stored centrally ("on for tenant acme, 10% of other users, off in the EU region").
  2. The application's SDK fetches the rules and caches them in memory, so checking a flag is a local lookup, not a network call.
  3. Each check passes an evaluation context: user ID, tenant, country, app version.
  4. Percentage rollouts hash the user ID, so the same user always gets the same answer.
  5. Every change is audited and pushed to running services within seconds.

You can buy this (LaunchDarkly, Statsig, ConfigCat), self-host open-source tools (Unleash, Flagsmith, flagd) or use a cloud service such as AWS AppConfig. OpenFeature, a CNCF incubating project, defines a vendor-neutral SDK so application code doesn't depend on one provider.

Example: rolling out a new checkout

import { OpenFeature } from "@openfeature/server-sdk"

const flags = OpenFeature.getClient()

const useNewCheckout = await flags.getBooleanValue(
  "new-checkout",
  false,                                    // default if the flag service is unreachable
  { targetingKey: user.id, plan: user.plan }
)

return useNewCheckout ? newCheckout(cart) : legacyCheckout(cart)

Week one: on for internal users only. Week two: 10% of customers, watching payment success rate. Week three: 100%. Week four: delete the flag, the legacyCheckout path and its tests. The deployment never changed during the rollout. This is how flags support canary releases at the feature level and the step-by-step migration in a strangler fig rewrite.

Feature flags in front-end and mobile apps

In React or a mobile app, evaluate flags on the server where possible, or fetch them at start-up and cache them. Anything shipped to the browser can be read, so never hide unreleased secrets or paid features behind a client-side flag alone. Enforce access on the server too.

Common mistakes

  • Flag debt. Give every release flag an owner and an expiry date, and fail the build or raise a ticket when it passes.
  • Unsafe defaults. Decide what happens when the flag service is down. The default above keeps the old, proven path.
  • Testing only one state. Run automated tests with the flag both on and off while both paths exist.
  • Nested flags. Three interacting flags create eight combinations nobody has tested.

We build products with trunk-based development and gradual rollouts through our product engineering work.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call