Feature flag

Also called: feature toggle, feature switch, feature gate

Last updated:

A feature flag is a conditional in your code whose value comes from remote configuration instead of being hard-coded, so you can change what the application does without shipping a release. Some teams call it a feature toggle. Feature flagging is the habit built on top of it: new work goes behind a flag, reaches production switched off, and gets released later by editing the flag. For each user, an SDK evaluates the flag and returns a variation. Boolean, string, number or JSON.

How a feature flag works

In code a flag is a branch, such as if (client.boolVariation('new-checkout', context, false)). Featureflip's server SDKs keep every flag's configuration in memory and evaluate it on the spot. No network call per check. The lookup takes well under a millisecond, and a change made in the dashboard streams out to long-running server processes, so the next evaluation on every server already uses it. Browser and mobile SDKs work the other way round. They receive values the server has already evaluated for their user, which keeps targeting rules off the device.

A feature flag example

A flag can carry more than on and off. Say checkout has two layouts and you want the new one in front of part of your traffic:
const layout = client.stringVariation('checkout-layout', { user_id: user.id, plan: user.plan }, 'classic')
In the dashboard, a targeting rule keeps every account whose plan is enterprise on classic, since their admins trained support staff on the old screens. Everyone else falls through to a 20% rollout of single-page. Sticky bucketing hashes the user ID, so one person sees the same layout on every visit. The flag's Analytics tab then counts the evaluations each layout got and the rule that served them. Going from 20% to 50%? A dashboard edit, with no release.

Why teams use feature flags

Flags split deploying code from releasing it. You ship to production with the feature off and widen it when you're ready, usually through a percentage rollout. Trunk-based development leans on this, since half-built work can merge to main every day behind a flag instead of sitting on a branch for three weeks and coming back as one painful merge. It also lets continuous delivery mean what it says. In the middle of an incident, an ops flag is a kill switch that acts faster than any rollback. Product and support get a lever too, since beta access or a plan-gated feature becomes a targeting rule they can change without filing a ticket. The feature flags concept guide covers variations, environments and the evaluation model in depth.

What feature flags cost

Every flag doubles the paths through the code it guards, and both paths need tests until the flag is gone. Release and experiment flags are meant to be temporary. The ones nobody removes become stale flags and then flag debt, branches nobody can explain, guarding a default picked by someone who left the team. Pete Hodgson's feature toggles article calls them "inventory which comes with a carrying cost". Plan the removal on day one. On Featureflip a flag can carry an owner and an expiration date, and the flag cleanup Action opens a pull request on GitHub, GitLab or Bitbucket that deletes a finished flag's code for you to review. Naming, testing, rollout and cleanup habits are collected in our feature flag best practices.

Want the full picture? Read the concept guide: What are feature flags? →

Try it in your own app

The Free plan covers 10 flags and 2 environments. No credit card, no demo call — sign up and ship.