Cloud
Feature Flags
Checking a flag is O(1): a single lookup, plus one extra calculation for a rollout flag. The real value is speed of change. Flipping a stored value is instant, compared to a full build-and-deploy cycle.
The idea, in plain English
A feature flag is a light switch for a piece of code. Flip it on, and users see the new feature. Flip it off, and they don't — right away, with no new code to deploy. Some flags are plain on/off switches for everyone. Others work more like a dimmer switch: they turn a feature on for only a share of users first, called a 'rollout.' This lets you try it on a small group before you flip it on for everyone else.
How it works
- 1Store each flag's setting somewhere the running app can read it, not baked directly into the code.
- 2For a simple flag, just check: is it on or off? Show the feature only if it's on.
- 3For a percentage rollout, use something stable about the user, like their user ID, to decide if they're in the rolled-out group. This way, the same user always gets the same answer.
- 4To change behavior, flip the flag's stored value. Every running copy of the app picks up the new setting right away, with no redeploy and no restart.
When you'd use it
Use this when you launch a risky or half-finished feature, run an A/B test, or need an instant 'off switch' for something misbehaving in production. Flags separate 'deploying code' from 'turning a feature on.' You can ship the code turned off, then flip it on later with zero downtime.
Common beginner mistakes
- Leaving old, unused flags in the code forever. Each one is a fork in the logic that someone still has to remember exists.
- Using something unstable, like the current time, to decide who's in the rollout. Then the same user flips between 'in' and 'out' on different requests.
- Forgetting that a flag is still code that needs testing. Both the on path and the off path have to actually work.
Try it — edit and run
Click the code to edit · press ⌘/Ctrl+↵ to run
Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.
Flag 'dark-mode' for user 7: on
Flag 'beta-banner' for user 7: off
Flag 'new-search' for user 7: on
Flag 'new-search' for user 42: off
After flipping the switch, flag 'dark-mode' for user 7: offNot sure this is the right topic? See the learning paths → or where this leads →