Feature flag
Фича-флаг
A switch that lets an application turn a feature on or off for everyone or for selected users. If the application can refresh the setting while it runs, changing the switch requires no redeployment.
Also known as: feature toggle
What a feature flag changes
A feature flag, also called a feature toggle, separates deploying code from releasing it to users. A team can ship a redesigned checkout to production on Monday and let employees try it on Tuesday, while customers still see the original. Both checkout flows are in the same build; the flag determines which one the application uses.
How the application makes the choice
A flag can be a single on/off value or a set of rules. The application evaluates those rules using context such as the environment, account ID, or membership in a beta group. For a 5% rollout, a common approach is to hash a stable user ID together with the flag key, map it to one of 100 buckets, and enable the feature for buckets 0 through 4. That keeps users in the same group across requests instead of giving them a fresh 5% chance each time.
A flag system often evaluates rules from a local copy of the configuration rather than making a network request for every page view. The copy still needs to be refreshed, so a change may take time to reach every instance. A flag read from an environment variable only at startup is simpler, but changing it usually requires a restart.
Example: rolling out a new checkout
use_new_checkout = flags.enabled('new_checkout', user_id=user.id, default=False)
return render_new_checkout() if use_new_checkout else render_old_checkout()
Here, the old flow is the fallback if the flag system has no usable configuration. The team can start with internal accounts, expand to a small share of customers, and compare checkout errors and completion rates between the two groups before expanding further. If errors rise, the team can turn off the flag without replacing the deployed build.
Where flags help and where they don't
Flags are useful for gradual releases, A/B tests, and emergency shutoffs. A canary deployment typically sends some traffic to a new application version; a feature flag can give users different behavior within the same version. Teams can use both in a single release.
Turning a flag off changes what happens next. It doesn't undo database writes or schema changes that already happened. A client-side flag isn't an authorization check either: hiding a button doesn't remove the need for the server to check permissions. Test both paths while a temporary flag is active, and assign someone to remove the flag and obsolete path once the rollout is complete.
How it comes up in interviews
You might be asked to design a 10% rollout with a quick shutoff. Explain what keeps users in the same group, how quickly updates reach running instances, and whether an instance uses its last known configuration or a defined default when it can't reach the flag service.