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.
| Component | Role | Typical implementation |
|---|---|---|
| Flag definition | Names the flag and its possible values | Key, type, default value |
| Targeting rules | Decide which value a context receives | Attribute matches, percentage splits |
| Evaluation SDK | Resolves the value inside the application | Local cache with streaming updates |
| Management console | Lets people change flags safely | Audit log, approvals, environments |
| Telemetry | Records which variant each user saw | Events linked to metrics |
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 type | Purpose | Expected lifespan |
|---|---|---|
| Release flag | Hide unfinished work merged to the main branch | Days to weeks |
| Experiment flag | Split users for A/B testing | Weeks, until statistical significance |
| Operational flag | Disable costly features under load | Long-lived, often permanent |
| Permission flag | Grant features to plans or beta groups | Long-lived, tied to the product |
| Kill switch | Turn off a risky component instantly | Permanent safety control |
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.
| Technique | Unit of control | Rollback speed |
|---|---|---|
| Feature flag | Individual feature, per user or segment | Seconds, by changing configuration |
| Canary deployment | Whole build on a share of servers | Minutes, by shifting traffic |
| Blue-green deployment | Whole environment | Minutes, by switching routing |
| Long-lived branch | Code that is not yet merged | Not applicable; nothing is deployed |
| Hotfix release | Complete new version | Hours, through the full pipeline |
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.
| Problem | Cause | Remedy |
|---|---|---|
| Stale flags in the codebase | No removal date or owner | Expiry dates and regular cleanup |
| Unexpected behavior in production | Untested flag combination | Limit dependencies between flags |
| Accidental exposure of a feature | Client-side rules reveal hidden work | Evaluate sensitive flags server-side |
| Latency on every request | Remote call per evaluation | Local cache with streamed updates |
| Outage after reusing a flag name | Old code still reads the key | Never repurpose retired flag keys |
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.