Feature flag

Also known as: feature toggle

On this page 7

A feature flag, also called a feature toggle, is a conditional switch in code that enables or disables functionality at runtime based on configuration, without building or deploying a new version. In the software lifecycle, feature flags separate deployment from release: code can ship to production while the feature stays hidden, then be turned on gradually, for chosen users, or rolled back in seconds.

Flags range from a single Boolean in a configuration file to a dedicated management platform that evaluates targeting rules per request. Their power comes with a cost, because every flag adds a code path that must be tested, monitored and eventually removed.

How feature flags are evaluated at runtime

A feature flag works by wrapping new behavior in a conditional check that asks a flag service or configuration source whether the feature is active for the current context. The context usually includes user identity, account, region, device or application version.

Evaluation can happen in several places. Server-side evaluation keeps rules private and consistent, while client-side evaluation in a mobile or browser application needs rules or precomputed results delivered to the device, which affects both latency and the confidentiality of unreleased features.

ComponentRoleTypical implementation
Flag definitionNames the flag and its possible valuesKey, type, default value
Targeting rulesDecide which value a context receivesAttribute matches, percentage splits
Evaluation SDKResolves the value inside the applicationLocal cache with streaming updates
Management consoleLets people change flags safelyAudit log, approvals, environments
TelemetryRecords which variant each user sawEvents linked to metrics
Main components of a feature flag system

Percentage rollouts rely on consistent hashing of a stable identifier, so the same user keeps seeing the same variant across sessions. Random assignment on every request would make behavior flicker and corrupt any experiment results.

Types of feature flags and their lifespans

Feature flags are not one thing; they fall into distinct categories with different owners, change frequencies and expected lifespans. Treating all of them alike is a major source of accumulated technical debt.

Flag typePurposeExpected lifespan
Release flagHide unfinished work merged to the main branchDays to weeks
Experiment flagSplit users for A/B testingWeeks, until statistical significance
Operational flagDisable costly features under loadLong-lived, often permanent
Permission flagGrant features to plans or beta groupsLong-lived, tied to the product
Kill switchTurn off a risky component instantlyPermanent safety control
Common categories of feature flags

Release flags are the most numerous and the most dangerous to forget. They should carry an owner and a planned removal date from the moment they are created, because a release flag left in place after the feature reaches general availability serves no purpose and only adds complexity.

Feature flags in the release process

Feature flags enable trunk-based development and continuous delivery by letting developers merge incomplete work to the main branch behind a disabled flag. This reduces long-lived branches and painful merges, which is especially valuable in agile software development with short sprints.

The table compares flags with other techniques that control how changes reach users. They are complementary rather than competing, and mature teams use several together.

TechniqueUnit of controlRollback speed
Feature flagIndividual feature, per user or segmentSeconds, by changing configuration
Canary deploymentWhole build on a share of serversMinutes, by shifting traffic
Blue-green deploymentWhole environmentMinutes, by switching routing
Long-lived branchCode that is not yet mergedNot applicable; nothing is deployed
Hotfix releaseComplete new versionHours, through the full pipeline
Feature flags compared with related release techniques

A typical progressive rollout moves a feature from internal staff to 1 percent, 5 percent, 25 percent and finally 100 percent of users, watching error rates and business metrics at each step. The flag also acts as a kill switch if a problem appears late, which often avoids an emergency hotfix entirely.

Managing flags safely

A flag change is a production change and deserves the same discipline as a code deployment. Turning on a flag for all users can have the same impact as releasing a new version, yet it may bypass review if governance is weak.

  • Give every flag a clear name, owner and type, recorded where engineers will see it.
  • Choose a safe default value that applies when the flag service is unreachable.
  • Require approvals and audit logs for changes to production flags.
  • Test both states of each flag, and avoid nested flags that multiply combinations.
  • Track flag age and schedule cleanup work as part of normal software maintenance.

Defaults deserve special care. If the flag service fails or the SDK cannot load configuration, the application falls back to the coded default, so a fail-safe default is usually the old, proven behavior rather than the new feature.

Risks, flag debt and common mistakes

The main long-term risk is flag debt: stale flags that clutter code, confuse readers and hide dead paths. With n independent Boolean flags, the number of possible combinations grows to 2 to the power of n, far beyond what any test suite can cover.

ProblemCauseRemedy
Stale flags in the codebaseNo removal date or ownerExpiry dates and regular cleanup
Unexpected behavior in productionUntested flag combinationLimit dependencies between flags
Accidental exposure of a featureClient-side rules reveal hidden workEvaluate sensitive flags server-side
Latency on every requestRemote call per evaluationLocal cache with streamed updates
Outage after reusing a flag nameOld code still reads the keyNever repurpose retired flag keys
Typical feature flag problems

A well-known industry failure illustrates the last row: reusing an old flag for new behavior activated dormant code on servers that had not been updated. The lesson is that flag keys should be unique for their entire lifetime and retired permanently once removed.

Understanding it simply

A feature flag works like a light switch built into the software. The new feature is already installed, but it stays dark until someone flips the switch, and it can be flipped back just as quickly.

This means a team can finish and ship code quietly, show the new feature to a small group first, and switch it off instantly if something goes wrong. The catch is that old switches must be removed once they are no longer needed, or the software becomes cluttered and harder to maintain.

Applied in practice

A banking application team rebuilds its money transfer screen. Development spans six sprints, and the new code is merged to the main branch every day behind a release flag that defaults to off, so the existing screen keeps serving customers throughout.

When the work is complete, the team enables the flag for employees, then for 2 percent of customers selected by consistent hashing. Dashboards compare completed transfers and error rates between the two groups. At 10 percent, a validation bug affects customers using one older phone model; the team turns the flag off in under a minute, fixes the code, and resumes the rollout the next day.

Three weeks later the new screen reaches 100 percent of users. The team then deletes the flag and the old screen code in a dedicated cleanup ticket, completing the release with no emergency hotfix and no lingering technical debt.