What is a feature flag?
A feature flag (or feature toggle) is a conditional in code allowing behaviour to be changed without deploying new code. The feature exists in the deployed application, and a configuration value decides whether it runs.
Why they are used:
Decoupling deployment from release. This is the central benefit. Code can be merged and deployed continuously while remaining invisible, then enabled when ready. It removes the pressure to hold long-lived branches, which are the source of painful merges.
Trunk-based development depends on this — merging incomplete work behind a flag rather than maintaining a separate branch for weeks.
Gradual rollout. Enable for 1% of users, watch the metrics and errors, then 10%, then everyone. This limits the blast radius of a problem enormously.
Instant rollback. Turning a flag off is far faster and safer than reverting a deployment, and it can be done by someone who is not deploying.
A/B testing and experimentation, serving different behaviour to different cohorts.
Targeted access — beta users, internal staff, specific customers, or a single account for debugging.
Operational kill switches, disabling an expensive feature under load.
The types matter, because they have different lifespans:
Release toggles — short-lived, removed once the feature ships.
Experiment toggles — removed when the experiment concludes.
Ops toggles — long-lived kill switches, deliberately permanent.
Permission toggles — effectively part of the product, controlling entitlements.
The main cost is complexity. Every flag doubles the number of code paths, and flags interact combinatorially. A codebase with dozens of stale flags becomes genuinely difficult to reason about and to test, since no test run covers every combination.
The discipline that makes it work: treat release flags as temporary by default, record an owner and a removal date, and schedule cleanup. Flag debt is real and accumulates silently.