A feature flag is a switch in your code. When it is on, users get the new behaviour. When it is off, they get the old one. The important part is that the switch lives outside your code, so you can flip it without building and deploying again.
Deploying is not releasing
Without flags, putting code on a server and showing it to users are the same event. With flags they are separate. You can deploy unfinished work safely because it stays hidden, and release it later, to the people you choose, when you are ready.
What teams use flags for
- Gradual rollouts. Show a feature to 5% of users, then 20%, then everyone.
- Targeted releases. Start with your own staff, then a beta group, then a region or a plan.
- Kill switches. Turn off a feature that is misbehaving, without a rollback deployment.
- Separate stages. A flag can be on in Staging and off in Production.
- Experiments. Serve different values to different groups and compare.
What it looks like in code
if (client.variation('new_checkout_flow', user, false)) {
renderNewCheckout();
} else {
renderCurrentCheckout();
}
The last argument is the default. It is what your code uses if the flag cannot be read, so make it the safe choice.
The trade-off
Flags are code paths, and every path needs testing and, eventually, removing. Give each flag an owner and a plan to delete it once the feature is fully released. We cover that in a separate article.
FlagDiligence gives you the dashboard, environments, targeting and SDKs to do this. Get started with the documentation.
