A feature flag is an if statement whose answer you can change without redeploying. It lets you ship new code to production switched off, turn it on for a few users first, and switch it off again in seconds if it misbehaves.
What a feature flag is
At its simplest, a flag is a named on/off value that your code checks before running a new code path. Say Kitty has built dark mode for her Tuna App. Instead of replacing the old theme outright, she wraps the new one in a check:
if (flags.isEnabled("dark-mode", { userId: cat.id })) {
renderDarkTheme();
} else {
renderLightTheme();
}Both paths are in the deployed code. Which one a user sees depends on the flag's current value, and that value lives outside the code: in a config file, a database row or, most often, a dedicated flag service. Change the value and the behaviour changes, with no new build and no new deployment.
The check takes the user as context, because a flag doesn't have to be the same for everyone. It can be on for the team and off for everyone else, or on for 10% of users. The flag service holds those rules, and your code only asks 'is this on for this user?'
Deploying is not releasing
Feature flags separate two things that usually happen together:
- Deploying puts a new version of the code on the servers.
Wondering how this was made? How we make these