Feature Flag
A feature flag, also called a feature toggle, is a switch in the code that turns a piece of functionality on or off without deploying new code. Teams use flags to ship unfinished work safely, release a feature to selected users first, run experiments and disable a misbehaving feature in seconds instead of rolling back a release.
How Feature Flags Work
The new code path sits behind a condition. At runtime the application asks a toggle router, often a configuration file or a flag management service, whether the flag is on for this request, user or environment. Changing the flag changes behavior with no new build or deployment.
Pete Hodgson's widely cited article on Martin Fowler's site groups flags into four categories:
- Release toggles hide incomplete features so code can be merged to the main branch early. They should usually live a week or two.
- Experiment toggles route users into variants for A/B testing.
- Ops toggles let operators switch off costly or risky behavior, sometimes as long-lived kill switches.
- Permissioning toggles give certain users, such as beta testers or premium customers, access to features, and can last for years.
Why Feature Flags Matter
Flags separate deployment (putting code into production) from release (making it available to users). That lets engineering practice continuous integration without exposing half-built work, and it lets product teams choose who sees a feature and when. A rollout to 5% of users, then 25%, then everyone limits the impact of a problem, and an off switch is faster than a hotfix.
Flags have a cost. Each one adds a branch to test and reason about. Hodgson recommends treating flags as inventory with a carrying cost and removing them once they have served their purpose, for example by adding a removal task to the backlog when the flag is created. Forgotten flags become a form of technical debt.
Feature Flag Example
A team building a new checkout flow merges code daily behind a flag called new_checkout, which is off in production. When the flow is ready, they turn it on for internal staff, then for 10% of customers while watching payment errors. Error rates stay flat, so they enable it for everyone. Two weeks later they delete the flag and the old checkout code.