Why you need it
Normally the moment new code is deployed, every visitor sees it. So shipping code and launching a feature happen together, and turning a bad feature off means another deploy. Teams want to put the code live early, and choose later when people see it.
Think of it like this
Turning on dark mode in an app's settings. Nothing new is installed. The app already had dark mode inside it; the switch only decides whether you see it.
Where you’ll find it
- GitHub: Puts new work behind flags so it can ship code safely and often, as told in how GitHub uses feature flags.
- LaunchDarkly and Unleash: Services that store flags and answer them for your code: LaunchDarkly and Unleash.
- AWS: AppConfig stores feature flags and changes them without a deploy.
- OpenFeature: An open standard for asking a flag from code, whichever flag service you use.
What to know first
Deploy. Putting a new version of the code live on the servers.
A few visitors first. Showing something new to a small share of visitors before the rest. See Canary releases.
How it works
- Deploy means show. Ben's new Buy now button is deployed, and every visitor gets it that same moment. This is the first picture in the animation.
- The code asks a question. Wrap the new part in a check, like
if flag("buy_now"):. The answer lives outside the code, in a flag service or a settings store. This is the flag card in the animation. - Deploy with the flag off. The new code is live on every server, but the flag says off, so visitors still get the old page. Deploying is now safe and boring.
- Turn it on, no deploy. On launch day someone flips the flag. The next request reads "on" and the button appears. If it misbehaves, flip it off again: seconds, not a new deploy. A flag kept for exactly this is often called a kill switch.
- Clean up. Flags can also be on for a share of visitors, like a canary. But every flag is an extra branch to test. Once a feature is fully launched, delete the flag and the old path.
An example
A new checkout is deployed on Monday with its flag off. Visitors see nothing new.
On Thursday at 09:00 the flag is turned on. Errors double by 09:05.
The flag is turned off at 09:06. The old checkout is back within seconds, with no deploy and no waiting for one.
Further reading
- Feature Toggles (aka Feature Flags), Pete Hodgson, on martinfowler.com. The standard guide: the kinds of flag, how long each should live, and how to keep them under control. Start with this one.
- How we ship code faster and safer with feature flags, GitHub blog. How a large team uses flags every day.
- Introduction, OpenFeature docs. What asking a flag looks like in code, the same way in any language.