What is a feature flag, and how would you implement one in a Node.js application to control a new feature's rollout?
Short answer
A feature flag is a runtime conditional determining whether code executes, letting a feature deploy dormant and be enabled gradually without a new deployment -- decoupling deploying code from releasing features, enabling instant rollback by flipping the flag off.
Advertisement
AModel answer
A feature flag is a runtime conditional determining whether code executes, letting a feature deploy dormant and be enabled gradually without a new deployment -- decoupling deploying code from releasing features, enabling instant rollback by flipping the flag off.
if (await isFeatureEnabled('new-checkout-flow', req.user)) {
return renderNewCheckout(req, res);
}
renderLegacyCheckout(req, res);Real-world example
A team rolls out a redesigned checkout behind a flag enabled first for employees, then 1%, 10%, and 100% of customers, able to instantly disable it if conversion rates dropped.
Likely follow-ups
- How do flags managed via a service like LaunchDarkly differ from a hand-rolled environment-variable flag?
- What's the maintenance burden of flags left in the codebase long after a feature fully rolls out?
Related topics