Feature flag (feature toggle)
A feature flag (also called feature toggle, feature switch, or feature flipper) is a software development technique that allows you to enable or disable features in your application without deploying new code. By wrapping features in conditional statements, teams can control who sees what, test features with limited audiences, and quickly disable problematic features without emergency deployments.
Why it matters
Feature flags have become essential for modern software development:
How feature flags work
Basic implementation
\\\`javascript
if (featureFlags.isEnabled('new-checkout-flow')) {
showNewCheckout();
} else {
showOldCheckout();
}
\\\`
Flag evaluation
Flags can be evaluated based on:
Types of feature flags
Release flags
Control when features become available:
Lifecycle: Temporary (remove after full rollout)
Experiment flags
Support A/B testing and experimentation:
Lifecycle: Temporary (remove after experiment concludes)
Operational flags
Control operational aspects of the system:
Lifecycle: Long-lived or permanent
Permission flags
Control feature access by user type:
Lifecycle: Permanent (often replaced by entitlements system)
Feature flag use cases
Gradual rollout
Release a feature to increasing percentages:
Monitor metrics at each stage; roll back if issues arise.
Canary releases
Test in production with minimal risk:
A/b testing
Compare variants scientifically:
Beta programs
Give early access to engaged users:
Kill switches
Disable features instantly:
Trunk-based development
All developers work on main branch:
Feature flag best practices
Naming conventions
Use clear, consistent names:
release-new-checkout (release flag)experiment-pricing-page-v2 (experiment)ops-enable-cache (operational)Default states
Choose defaults carefully:
Flag documentation
Maintain flag documentation:
Regular cleanup
Remove obsolete flags:
Testing
Test both states:
Monitoring
Monitor flag-related metrics:
Feature flag risks
Flag proliferation
Too many flags create complexity:
Mitigation: Regular cleanup, flag limits, ownership requirements
Configuration drift
Production differs from other environments:
Mitigation: Environment-specific testing, flag parity
Testing challenges
Multiple flag combinations multiply test cases:
Mitigation: Test critical paths, use default states, limit flag interactions
Performance impact
Flag evaluation can add latency:
Mitigation: Local caching, simple rules, performance monitoring
Feature flag architecture
Client-side flags
Evaluated in the browser/app:
Server-side flags
Evaluated on the server:
Hybrid approach
Combine both:
Feature flag tools
Self-hosted
Managed services
Klero integration
Klero complements feature flags by:

