A feature flag (also called a feature toggle) is a conditional switch in your codebase that controls whether a feature is visible or active for users. Instead of deploying a feature to everyone at once, you wrap it in a flag and control who sees it — by percentage, user segment, geography, or any other criteria.
How Feature Flags Work
At their simplest, a feature flag is an if/else statement:
if (featureFlags.newCheckout) {
showNewCheckout()
} else {
showCurrentCheckout()
}
The flag value is controlled externally — through a dashboard, config file, or feature management platform — so you can toggle features on or off without redeploying code.
Common Use Cases
- Gradual rollouts — Release a feature to 5% of users, then 25%, then 50%, then 100%, monitoring for issues at each step
- A/B testing — Show different feature variants to different user groups and measure which performs better
- Kill switches — Instantly disable a feature that's causing problems in production
- Beta programs — Give early access to specific users or accounts
- Regional releases — Launch features in specific markets before a global rollout
Feature Flags and CRO
In conversion rate optimization, feature flags serve as the delivery mechanism for experiments. They determine which variant a visitor sees and ensure consistent experiences across sessions. Most modern experimentation platforms — including Surface AI, Optimizely, and LaunchDarkly — use feature flags under the hood.
Risks to Manage
Feature flags introduce technical debt if not cleaned up. Old flags left in the codebase create confusion and potential bugs. Best practice is to remove flags once a feature is fully rolled out or permanently killed.