Table of Contents
Feature flag
Feature flag is a conditional in code that enables or disables a feature at runtime without deploying new code. The feature is deployed but dark; it is activated by changing a configuration value.
Releasing new features creates risk: if something breaks, rolling back the entire deployment is expensive and slow. Incomplete features merged to the main branch also cause delays while waiting for independent components to be ready before shipping.
Feature flags enable progressive rollout (1% of users first, then more), instant kill switches if things break, trunk-based development (merge incomplete features but keep them dark), and A/B testing different configurations. The tradeoff is that old flags accumulate as dead code, and complex flag combinations become hard to test. Teams need a hygiene practice of removing flags after rollout.
Here a feature flag gates a new checkout flow: targeting criteria determine who sees which variant.
// Example: feature flag in a web application
function renderCheckout(user) {
if (featureFlags.isEnabled('new-payment-flow', user)) {
return <NewPaymentFlow />;
} else {
return <LegacyPaymentFlow />;
}
}
// Configuration (could be database, environment, or feature service)
const featureFlags = {
'new-payment-flow': {
enabled: true,
rolloutPercent: 25, // 25% of users see new flow
targetUser: (user) => user.betaTester || Math.random() < 0.25
}
};
