Feature toggles are a software development technique that allows you to turn parts of a website or application on or off without deploying new code. Also known as feature flags, bits, or flippers, they enable teams to ship new functionality rapidly while minimizing the risk of a site-wide crash. By wrapping new code in a conditional statement, you can control exactly who sees a feature and when it goes live.
Entity Tracking
- Feature Toggle: A technique allowing developers to enable or disable software features at runtime without deploying new code.
- Toggle Point: The specific conditional statement in a codebase that routes a user to one of two feature paths.
- Toggle Router: The logic layer that determines which feature path is active based on user context or configuration data.
- Canary Release: A strategy where a new feature is rolled out to a small percentage of users to test stability before a full launch.
- Release Toggle: A temporary flag used to hide incomplete code so a team can integrate work into a shared branch continuously.
- Ops Toggle: A control used by systems operators to quickly disable features during performance issues or high server load.
- Experiment Toggle: A flag used for multivariate or A/B testing to compare how different user cohorts interact with variants.
- Permissioning Toggle: A long-lived flag that grants specific features only to certain user groups, such as premium or internal users.
What is a Feature Toggle?
A feature toggle provides an alternative to maintaining multiple branches in source code. Instead of waiting for a massive "release day," developers integrate unfinished features into the main code branch. The code remains in a latent state, hidden from the user interface until the toggle is flipped.
While the terms are often used interchangeably, some practitioners make a distinction. A "toggle" refers to the broad practice of controlling visibility at runtime, while a "flag" is the specific code-level construct, such as a boolean value, that makes the toggle possible. [Using "feature flag" rather than "feature toggle" to describe hiding partially built features in 2020] (Martin Fowler) became a preferred convention for describing advanced release mechanisms.
Why Feature Toggles matter
Feature toggles allow marketing and product teams to move faster and make decisions based on data rather than the opinions of the highest-paid people (HiPPOs).
- Risk Mitigation: Instantly disable a new search algorithm or checkout flow if it tracks a spike in errors or a drop in conversion.
- Decoupled Releases: Engineers can deploy code on a Tuesday, while the marketing team "releases" the feature on a Thursday to coincide with a campaign.
- Canary Testing: Roll out a feature to a [random sampling of 1% of the user base] (Martin Fowler) to monitor performance before a 100% rollout.
- A/B Testing: Compare two different call-to-action buttons or recommendation algorithms by routing user cohorts to different code paths.
- Operational Safety: Use "Kill Switches" to gracefully degrade non-vital site features, like a recommendations panel, during high-traffic events to save server resources.
Types of Feature Toggles
Managing all toggles the same way is dangerous because they serve different purposes and have different lifespans.
| Type | Longevity | Dynamism | Primary User |
|---|---|---|---|
| Release | Days/Weeks | Static | Developers |
| Experiment | Weeks | Highly Dynamic | Product Managers |
| Ops | Short or Long | Highly Dynamic | System Operators |
| Permissioning | Months/Years | Highly Dynamic | Product/Marketing |
How Feature Toggles work
The implementation relies on three main components that separate the decision to show a feature from the code that runs the feature.
- Toggle Point: This is an
if/elsestatement in the code. It asks the system, "Is this feature enabled?" If yes, it runs the new code; if no, it runs the legacy code. - Toggle Router: This is the brain of the system. It checks the configuration to decide which path the user should take. For A/B tests, the router uses a cohorting algorithm to ensure a user stays in the same test group throughout their session.
- Toggle Configuration: This is where the state (on/off) or rules (only users in New York) are stored. This can be a simple file, a database entry, or a dedicated feature management platform.
Best practices
Follow these steps to keep your site fast and your codebase clean.
- De-couple decision logic: Do not bake the reason for a toggle into the feature code. Use a "Feature Decisions" object so you can change a toggle from an A/B test to a permanent release in one place.
- Prefer static configuration: Whenever possible, manage your toggles through source control. This ensures the configuration moves through your delivery pipeline with the code it controls.
- Expose current states: Create a metadata API or dashboard so your team can quickly see which features are currently live in production.
- Limit your inventory: Treat toggles like inventory with a carrying cost. Removing them requires a proactive plan, such as adding a "toggle removal" task to your backlog the moment a flag is created.
Common mistakes
Mistake: Using a Release Toggle for too long. Fix: Remove the flag within a week or two. [A release toggle should be your last choice for putting features into production] (Martin Fowler); instead, try breaking features into smaller, safer parts.
Mistake: Failing to clean up "dead" toggle code. Fix: This creates "toggle debt." Implement "time bombs" in your tests that fail if a toggle exists past its expiration date.
Mistake: Neglecting the testing burden. Fix: You must test the site with the toggle On and Off. While you do not need to test every combination of every flag, you must validate the "fallback" state to ensure the site works if you have to hit a kill switch.
Mistake: Forgetting the historical risks of mismanaged flags. Fix: Learn from the [Knight Capital Group's $460 million dollar mistake] (Doug Seven), which was caused by incorrect manual configuration of old code.
Examples
Example scenario: Internal Testing (Champagne Brunch) A team wants to test a new "Log in with Facebook" button. They use a Permissioning Toggle to show the button only to internal employees. This "Champagne Brunch" allows staff to use the feature in the live production environment without exposing it to the general public.
Example scenario: Ops Kill Switch An e-commerce site faces extreme traffic during a product launch. The operations team uses an Ops Toggle to disable the "Customers also bought" recommendation engine. This reduces server load on the database and ensures the main "Purchase" button continues to function for all users.
FAQ
What is the difference between a Canary Release and a Champagne Brunch? A Canary Release exposes a feature to a randomly selected group of users, usually for performance monitoring. A Champagne Brunch targets a specific, non-random group (usually internal staff) so they can "drink their own champagne" and find bugs before customers do.
Can marketers use feature toggles without developers? While developers must create the initial Toggle Point in the code, many modern platforms provide a GUI dashboard. This allows marketers or product managers to change targeting rules, flip kill switches, or adjust A/B test percentages without writing code.
How long should a toggle stay in the code? Release toggles should stay for a few days. Experiment toggles stay as long as it takes to reach statistical significance. Permissioning toggles, like those for "Premium Users," can stay for years.
Do feature toggles slow down the website? If placed at the "edge" (where the user first hits the app), a toggle point is just a simple conditional check. However, having hundreds of unmanaged toggles can increase complexity. Using a distributed configuration system like Consul or Zookeeper helps update all servers instantly without performance lag.
What happens if a toggle is disabled in production? The system should follow the "if/else" logic to the "else" path. A good convention is to ensure that the "else" path always leads to the stable, legacy version of the feature.