Feature Flag
A feature flag (also called a feature toggle) is a switch that turns a feature on or off without deploying new code. Pete Hodgson's article on martinfowler.com describes it as a technique that lets teams change system behavior without changing code, and groups flags into four categories by purpose: release, experiment, ops and permissioning.[1] Teams use flags to ship unfinished features in a hidden state, to roll a feature out to a percentage of users or a specific group, and as a kill switch that turns off a single feature when something goes wrong.[1][3] The trade-off is cost: every flag adds conditional logic and more code paths to test.[1]
What does Feature Flag mean in simple terms?
Think of the light switches in each room of a building. Instead of rebuilding the whole building to open a new room, you finish the room in advance and flip its switch later. If something goes wrong, you flip the switch back off. Feature flag tools apply the same idea per user: a flag can describe several variations of a feature and rules for who sees which one, such as a percentage of traffic, specific people, or users with a shared attribute like location or device type.[3]
How can Feature Flag be explained with an analogy?
A light switch for each room. The room is built ahead of time, and the light is turned on only when you are ready.
Where is Feature Flag used?
Daangn Pay — Toward daily deployments
A backend engineer on Daangn Pay's money service team described how feature toggles supported the team's move to deploying every day.[5] Their design rules: when a toggle is on, the new behavior runs, and when it is off, the existing behavior runs; the toggle point in the code is separated from the logic that decides on or off; toggle settings can change without a deployment; and unused toggles are removed right away.[5] The team also built a permissioning toggle that turns a feature on only for listed users, such as staff, and a canary toggle that exposes a feature to a set percentage of users.[5]
Result: The author's own view is that feature flags account for "70% or more" of what made daily deployment possible. This is a personal estimate, not a measured figure.[5]
Woowa Brothers — An experimentation platform
Woowa Brothers, which runs the Baemin delivery app, built an internal platform that handles both A/B experiments and feature flags. It has an admin screen for creating experiments and flags, a server that assigns users to groups, event collection, and Airflow-based aggregation, and it checks results with a Z-test.[4] The same platform supports ops-style flags, for example switching between two external map providers if one fails.[4]
Result: Users are hashed into 10,000 logical slots for consistent assignment; results can be judged at 95% or 99% confidence; and flag data is cached locally for only 30 seconds so that changes take effect quickly (2023-01-05).[4]
GitLab — A public flag policy
GitLab develops its own product behind feature flags and publishes the rules. New flags should be disabled by default and used with an "actor" such as a user, project or group, and a flag must be used in the same merge request that introduces it.[6] Each flag type has a maximum lifespan after it is merged, so flags do not linger.[6]
Result: Maximum lifespans of 2 months (gitlab_com_derisk), 4 months (wip) and 6 months (beta and experiment); ops flags have no fixed limit but must be re-evaluated every 12 months.[6]
Etsy — Open-sourcing an internal flag API
Etsy released the PHP feature-flag API it used for gradual operational ramp-ups and A/B tests.[7] Most code needed only two entry points: one that checks whether a feature is enabled and one that picks a variant. A feature could be ramped up to, say, 1% of users for a smoke test and turned fully off in an emergency by setting it to "off".[7] The repository notes that it is no longer maintained or in sync with Etsy's internal version.[7]
Result: Two main API calls (isEnabled and variant); repository archived and read-only since 2019-12-18.[7]
Try it today
- Pick one feature that will go into your next deployment.
- Create a flag that is off by default, and keep the place in the code that checks the flag separate from the logic that decides on or off.[1][5][6]
- Turn it on only for internal accounts and check it in the real environment.[5]
- Raise exposure step by step (for example 1%, then 5%, then 20%) while watching error rates. If problems appear, turn the flag off.[7]
- For a temporary release flag, once the feature is stable at 100%, put a removal deadline for the flag in a ticket on the backlog.[1]
Limits and direction
Flags are not free. Hodgson writes that toggles bring new abstractions and conditional logic into the code and add a significant testing burden.[1] Every flag means at least some tests must run with it both on and off, and with many flags the number of possible combinations explodes; each independent on/off flag doubles the number of possible configurations.[1] He notes that effective teams treat flags as inventory with a carrying cost and keep that inventory as low as possible.[1] Martin Fowler adds that release flags should be a last resort: first try to split a feature into small parts that can be released safely.[2]
Forgotten flags also create risk. Unleash's documentation explains that stale flags left after their purpose is served can expose sensitive features or data by accident, and that stale or conflicting flags can cause unexpected behavior and downtime.[8] Teams respond in several ways: GitLab sets maximum lifespans by flag type, Daangn Pay removes unused toggles right away, and Hodgson describes expiration dates, failing tests for expired flags, and caps on the total number of flags.[1][5][6]
Which sources explain Feature Flag?
- martinfowler.com (Pete Hodgson) — Feature Toggles (aka Feature Flags) (published 2016-01-19 to 2016-02-08, revised 2017-10-09) — https://martinfowler.com/articles/feature-toggles.html
- martinfowler.com (Martin Fowler) — bliki: Feature Flag (2010-10-29, revised 2023-07-14) — https://martinfowler.com/bliki/FeatureFlag.html
- LaunchDarkly Docs — Using feature management — https://launchdarkly.com/docs/home/getting-started/feature-management
- Woowa Brothers Tech Blog — Building an experimentation platform for experiments and feature flags (Korean, 2023-01-05) — https://techblog.woowahan.com/9935/
- Daangn Tech Blog (Medium) — The journey to deploying every day, part 2: Using feature toggles (Korean, 2023-04) — https://medium.com/daangn/%EB%A7%A4%EC%9D%BC-%EB%B0%B0%ED%8F%AC%ED%95%98%EB%8A%94-%ED%8C%80%EC%9D%B4-%EB%90%98%EB%8A%94-%EC%97%AC%EC%A0%95-2-feature-toggle-%ED%99%9C%EC%9A%A9%ED%95%98%EA%B8%B0-b52c4a1810cd
- GitLab Docs — Feature flags in the development of GitLab — https://docs.gitlab.com/development/feature_flags/
- GitHub — etsy/feature: Etsy's Feature flagging API (repository archived 2019-12-18) — https://github.com/etsy/feature
- Unleash Docs — Technical debt (managing feature flag technical debt) — https://docs.getunleash.io/concepts/technical-debt
Tell us what you think
Your feedback helps us improve the content.