Feature Flag Implementation: Gradual Rollouts, Kill Switches and Keeping Flags Under Control
How to implement feature flags: release, experiment, ops and permission flags, gradual rollouts, kill switches, access control, testing, governance and cleanup.
How should teams implement feature flags?
Use flags to separate deploying code from releasing features: deploy behind a flag, release to internal users, then a small share of customers, then everyone, with a kill switch ready. Classify flags by purpose, give each an owner and expiry, control who can change them in production, test important combinations, and remove flags once they have done their job. Flags reduce release risk; unmanaged flags create new risk.
This guide is for engineering leads and product teams adopting or tidying up feature flags. It covers flag types, a step-by-step implementation, percentage rollouts, kill switches, build-or-buy choices, mobile apps, experimentation, governance, access control and cleanup. For release practices around flags, see DevOps for growing businesses.
Key takeaways
- Classify flags: release, experiment, operational, permission.
- Every flag has an owner, a purpose and an expiry or review date.
- Production changes are permissioned and audited.
- Kill switches are simple, tested and in runbooks.
- Backends enforce entitlements; flags are not authorisation.
- Remove release and experiment flags promptly.
Types of flags
Pete Hodgson's article on martinfowler.com describes categories of toggles with different lifetimes:
| Type | Purpose | Lifetime |
|---|---|---|
| Release | Hide unfinished or new features until ready | Days to weeks; remove after rollout |
| Experiment | Split users between variants for testing | Length of the experiment |
| Operational | Kill switches, load shedding, degrading gracefully | Long-lived, deliberately |
| Permission / entitlement | Features by plan, customer or role | Long-lived, backed by server checks |
How to implement feature flags, step by step
The mechanics are simple; the discipline around them is what keeps flags useful. This sequence works for a first flag and scales to hundreds.
- Decide where each flag is evaluated. Evaluate on the server for anything that affects money, data access or security. Client-side evaluation is fine for presentation-only changes.
- Choose storage and delivery. A configuration file or database table is enough for a handful of on/off flags. Move to a flag service with SDKs when you need targeting, percentage rollouts and an audit history.
- Set a naming convention and required metadata. Record type, owner, creation date, expiry or review date and the linked ticket for every flag.
- Wrap evaluation in one small interface. Call sites ask "is this enabled for this user?" through your own function, so the provider can change without touching every call site.
- Define safe defaults. Decide what each flag returns if the flag service is slow or unreachable. For new features, that is usually off.
- Record flag state in logs and analytics. When investigating an incident or reading an experiment, you need to know which variant a user saw.
- Create the removal task when you create the flag. Release and experiment flags should have a planned end.
type FlagKey = "new-checkout" | "pricing-page-test";
// Every flag check in the codebase goes through this function.
export async function isEnabled(
key: FlagKey,
ctx: { userId: string; accountId: string; plan: string },
): Promise<boolean> {
try {
// flagProvider wraps your config table, flag service or OpenFeature client.
return await flagProvider.getBoolean(key, ctx, false); // default: off
} catch {
return false; // fail safe if the provider is unavailable
}
}Gradual rollouts and kill switches
- Roll out in stages: internal users, a few customers or a small percentage, then wider.
- Watch error rates, latency and key journeys at each stage; see application monitoring.
- Define in advance what triggers a rollback, and who decides.
- Keep kill switches for risky dependencies, such as third-party APIs and AI features.
- Make sure flag evaluation fails safe if the flag service is unavailable.
Percentage rollouts: keep assignment consistent
A percentage rollout should put the same user in the same group on every request and every device. The usual approach is to hash a stable identifier, such as the user or account ID, together with the flag key, and compare the result with the rollout percentage. Random assignment on each request makes features flicker on and off and makes bug reports impossible to reproduce.
For B2B products, roll out by account rather than by user, so colleagues in the same company see the same version of a screen. Raise the percentage in planned steps, and only after checking the metrics agreed for that stage.
Build or buy a feature flag system
Most teams start with configuration and outgrow it. Pick the simplest option that covers the next year of needs. OpenFeature, a vendor-neutral specification hosted by the Cloud Native Computing Foundation, defines a common API for flag evaluation, which makes it easier to change provider later.
| Option | Fits when | Trade-off |
|---|---|---|
| Configuration file or environment variables | A few release flags; changing them through a deploy is acceptable | No targeting or percentages; every change is a deploy |
| Database table with an admin screen | Dozens of flags, mostly on/off by account or plan | You build auditing, permissions and caching yourself |
| Self-hosted open-source flag server | Targeting and percentage rollouts needed; data must stay in your infrastructure | You run, secure and upgrade it |
| Commercial flag service | Several teams and platforms, frequent experiments, audit requirements | Subscription cost and vendor dependency; keep your own interface in front of it |
Feature flags in mobile apps
Mobile apps add constraints. Users run old versions for months, the app must cache flag values for offline use, and a flag cannot switch on code that is not in the installed build. Ship new code paths switched off in a release, cache flag values with sensible defaults, and keep kill switches for features that depend on your servers or third-party services. Combine flags with the app stores' staged rollouts; see mobile app release management and offline-first app development.
Experimentation
Experiment flags assign users consistently to variants and record exposure for analysis. Keep experiment logic separate from release flags, define success and guardrail metrics before starting, and avoid declaring results from underpowered tests. See A/B testing and experimentation mistakes.
Governance and access control
- Restrict who can change production flags; require approval for high-impact flags.
- Audit every change: who, when, what and why.
- Use consistent evaluation across services; an open standard such as OpenFeature can help.
- Document each flag's purpose, owner and removal plan.
- Review the flag list monthly and remove stale flags.
Testing with flags
Test the default path and the flagged path for every release flag, and test the combinations that matter, not every possible combination. Run automated tests with production-like flag configurations. Keep flag state in test fixtures explicit so tests do not depend on a remote service. See automated regression testing.
Cleanup
Stale flags are technical debt: dead code paths, confusing configurations and surprise behaviour when someone flips an old flag. Set an expiry when creating release and experiment flags, create the cleanup task at the same time, and track flag age. Removing a flag is a small, low-risk change when done promptly.
Common mistakes
- Using flags as the only check on paid features.
- Hundreds of flags with no owners.
- Production flag changes without audit.
- Kill switches nobody has tested.
- Flags evaluated differently in web, mobile and backend.
Related guides
For related guides, see application monitoring, SaaS onboarding optimisation for experiment ideas and architecture review for flag-related technical debt.
Conclusion
Feature flags make releases safer and experiments possible, if they are treated as part of the system: typed by purpose, owned, audited, tested and removed when done. Use them to decouple deployment from release, keep kill switches for risky dependencies, and never let a flag stand in for authorisation. For deployment strategies that pair with flags, see zero-downtime deployments.
Want safer releases?
ZSpace Labs is an India-based, remote-first technology studio working with Australian and international businesses on web applications and mobile apps released with flags, staged rollouts and monitoring. If it would help to review your release process, we are happy to talk it through.
Common questions.
A feature flag, or feature toggle, is a switch in code that turns behaviour on or off, or chooses between variants, without deploying new code. Flags let teams deploy unfinished work safely, release gradually, run experiments, switch off a failing feature quickly and control access by customer or plan.
For a few simple flags, configuration in your application may be enough. As flags grow, a feature flag service or open standard such as OpenFeature helps with targeting, auditing, gradual rollouts and SDKs across platforms. Building a full system yourself is rarely worth it unless you have unusual requirements.
A kill switch is a flag that disables a feature or dependency quickly when it misbehaves, such as switching off a recommendation widget if its service fails. Kill switches should be simple, tested, documented in runbooks and usable by on-call staff without a deployment.
Common failures are flags that are never removed, creating dead code and confusing combinations; flags changed in production without review or audit; flags evaluated inconsistently between services; and untested flag combinations that break when turned on. Governance, ownership, expiry dates and testing prevent most of these.
Flags can gate features by plan or customer, but they are not a substitute for server-side authorisation. If a flag hides a feature in the interface, the backend must still check that the user is entitled to use it. Never evaluate security-critical flags only in client code.
Decide where each flag is evaluated (server-side for anything sensitive), choose storage (configuration for a few flags, a flag service for targeting and rollouts), set naming and ownership rules, wrap every check in one interface with a safe default, record flag state in logs and analytics, and create the removal task at the same time as the flag.
A feature flag is the mechanism that switches behaviour on or off for chosen users. An A/B test uses that mechanism to assign users to variants consistently and measure the effect on agreed metrics. Every A/B test needs a flag, but most flags are for releases and kill switches, not experiments.