Most teams think of feature flags as a developer convenience: a way to merge code to main without showing unfinished features to users. Wrap the new code path in an if statement, flip the flag when it's ready, move on. That's where everyone starts, and a lot of organizations never get further. Their flags are a glorified code comment.
Treated as infrastructure, flags do a good deal more. They are a safety net for deployments, a kill switch during incidents, and the way you roll a feature out in stages. Above all they separate deployment from release, which is one of the most useful separations in software delivery.
Deployment Is Not Release
Deploying code and releasing functionality are two different operations. Deployment puts new code on production servers. Release makes that code active for users. Without feature flags the two are one event: you deploy, and whatever is in the build is live. If it's broken, you roll back the deployment, and the blast radius is everyone.
With flags, you deploy code that sits on the server inactive. You release the feature by enabling the flag for a subset of users, a specific region, or internal testers first, and then gradually for everyone. If something goes wrong, you disable the flag. There is no redeployment, no rollback, and no waiting on a CI/CD pipeline. The bad code path is off in seconds.
This matters most in incident response, where the question is how fast you can stop the bleeding. Rolling back a deployment takes minutes at best: build the previous artifact, push it through the pipeline, wait for instances to drain and restart. Toggling a flag takes seconds. The new code path goes off, the old one takes over, and the incident is contained while you figure out what went wrong.
Kill Switches
Every critical feature in production should have a kill switch. I don't mean the rollout flag. I mean a dedicated, permanent flag whose only job is to turn that feature off if it becomes a problem. It matters most for features that talk to external systems, process payments, or handle data that can't easily be recovered.
I've been in incidents where a third-party API started returning errors at a rate that overwhelmed our retry logic, which backed up the queues, which raised latency across the entire platform. The fix was turning off the feature that called that API. With a kill switch that is a 10-second operation. Without one it is a deployment in the middle of an active incident, under pressure, by engineers who are already switching between diagnosis and mitigation.
Kill switches are infrastructure and should be run like it:
- Keep them permanently. They don't get cleaned up when the feature is "stable," because the flag is there for emergencies and has nothing to do with rollout.
- Make them independent of deployment. Toggling a kill switch is a configuration change evaluated at runtime and should never need a code deployment.
- Give on-call access. The on-call engineer should be able to flip a kill switch without understanding how the feature is built, which means clear names, clear documentation, and working permissions.
- Test them regularly. If you've never turned a kill switch off in production, you don't know that it works. Check that disabling the flag stops the bad behavior and has no side effects.
Progressive Rollouts
The default deployment model is binary: code is live for everyone or for nobody. Feature flags turn the rollout into a gradient. You can release to 1% of users, watch the metrics, then go to 5%, then 25%, then 100%, and you can halt or roll back at any point.
A binary deployment makes every release an all-or-nothing bet. A progressive rollout makes it an experiment whose blast radius you set. If the new payment flow has a bug, it reaches 1% of users. You catch it sooner, fix it with less damage, and you are working from real production data on top of whatever staging told you.
Two mechanics matter. The first is sticky assignment. A user who sees the new experience should keep seeing it on later requests, because assigning at random per request gives people an inconsistent product and makes debugging impossible. Hash the user ID against the flag to decide assignment. Each user then gets a consistent experience while the population as a whole is still split at random.
The second is metric gates. Define the metrics that decide whether the rollout proceeds: error rate, latency, conversion rate, whatever matters for that feature. If they degrade past your threshold at any percentage, the rollout should halt automatically. Don't count on a human noticing a dashboard. Wire the metrics into the flag system so the rollout pauses itself.
The Danger of Permanent Flags
Flags get dangerous when they stay forever. A flag is created for a rollout, the rollout completes, the feature is live for 100% of users, and the if/else branch stays in the code because nobody removes it. The code now has two paths. One runs. The other doesn't, but it is still maintained, still compiled, still tested (maybe), and still in the head of every developer who reads that code.
This is flag debt, and it builds up the way technical debt does. One stale flag is harmless and twenty are a maintenance burden. With two hundred, nobody can say with confidence what is running. I've seen codebases where flags referenced features that had launched two years earlier. The "off" path was dead code that had drifted so far from the current architecture that it wouldn't have worked if someone had disabled the flag by accident. A flag like that is a trap.
So flag hygiene isn't optional. Every flag should have four things:
- An owner, responsible for the flag's lifecycle. When that person leaves the team, ownership is handed over explicitly.
- An expiration date by which the flag is fully rolled out and removed from code. Make it a deadline that triggers alerts.
- A type: release flag (temporary, for rollout), ops flag (permanent, for kill switches), experiment flag (temporary, for A/B testing), or permission flag (long-lived, for entitlements). The type sets the lifecycle.
- A removal ticket, created at the same time as the ticket to add the flag. Removing a release flag is part of the feature's definition of done.
Centralized Flag Management
If your flags are defined in config files scattered across repositories, what you have is a set of conditionals. A flag system is centralized, evaluated at runtime, and observable.
Centralized means one place shows every flag, its current state, who changed it, and when. Runtime-evaluated means changing a flag needs no deployment: the application reads flag state from the central system on each evaluation, with appropriate caching. Observable means you can see which flags are being evaluated, how often each path is taken, and what it costs in performance.
There are solid options. LaunchDarkly is the most established commercial platform. Unleash and Flagsmith are strong open-source alternatives. OpenFeature is working on a standard API so you can switch providers without rewriting your flag evaluations. The tool matters less than the principles: centralized management, runtime evaluation, audit logging, and a clear lifecycle model.
What you should not do is build your own flag system from scratch. I've seen it repeatedly. A team decides that flags are "just config" and builds a key-value store on a database table with a simple API. Six months later they've reinvented targeting rules, percentage rollouts, audit logging, and multi-environment support, and they maintain a homegrown system with none of the reliability or features of the off-the-shelf options. In this category buying, or adopting open source, beats building almost every time.
Flags for Experimentation
Feature flags and A/B testing fit together. The flag decides which code path runs. The experiment framework decides which users get which path and measures the outcome.
A rollout flag and an experiment flag differ in intent. A rollout flag gradually exposes a feature you've already decided to launch, and its metrics watch for regressions. An experiment flag exists to find out whether you should launch at all, and its metrics measure improvement.
Experiment flags need statistical rigor that rollout flags don't: sample size calculations, proper control groups, significance thresholds, and enough duration to avoid novelty effects. Doing it well takes both engineering and analytical discipline.
Experiment flags also tend to live longer than rollout flags, which makes cleaning them up more important. An experiment that concluded three months ago with its flag still in the code is worse than a stale rollout flag, because that code was written specifically to make behavior diverge. Remove it as soon as the experiment ends and the decision is made.
The Operational Maturity Model
You can gauge a team's operational maturity by how it uses feature flags. This is the progression I typically see.
Level 1: Code Hiding
Flags hide unfinished features in main. They are hardcoded booleans or environment variables, with no central management and ad hoc cleanup. Most teams start here and many stay.
Level 2: Controlled Rollout
Flags support percentage-based rollouts and user targeting, and a central system manages flag state. The team uses flags for every production release and has a process for cleaning up once a rollout completes.
Level 3: Operational Tooling
Flags are integrated with incident response. Kill switches exist for critical features, and on-call engineers know how to use the flag system. Flag changes are audit-logged and tied to incident timelines, and flag state is part of the operational runbook.
Level 4: Automated Safety
Rollouts are automated with metric gates. The system monitors error rates, latency, and business metrics during a rollout and halts or rolls back automatically when thresholds are exceeded. Stale flags trigger automated alerts, and policy enforces the flag lifecycle.
Most teams are at Level 1 or 2. The jump from Level 2 to Level 3, where flags stop being development tooling and become operational infrastructure, is where the biggest return is. From there on, flags are part of how you operate production safely.
Getting This Right
Whether you're starting from scratch or cleaning up a messy flag system, I'd go in this order:
- Adopt a centralized flag system. Stop managing flags in config files and environment variables. Use a purpose-built tool, commercial or open-source, that gives you runtime evaluation, targeting, audit logging, and a management UI.
- Classify your flags. Tag every flag as release, ops, experiment, or permission, and let the classification set the lifecycle rules. Release flags expire, ops flags are permanent, and experiment flags last as long as the experiment.
- Implement kill switches for critical features. Identify the features whose failure would do the most damage, add kill switches, test them, and make them accessible to on-call.
- Enforce flag hygiene. Set expiration dates and alert when flags are past their expected lifecycle. Track flag count as a metric: if the number only ever grows, you have a cleanup problem.
- Wire flags into your incident response. When an incident occurs, the first question should be "Did any flags change recently?" Responders need flag change history at hand, correlated with deployment history and metric changes.
A feature flag is the smallest unit of operational control you can add to your system. It costs almost nothing to implement, and it earns that back many times over during deployments, incidents, and experiments.
Feature flags are infrastructure in the same way that load balancers, monitoring, and deployment pipelines are. Teams that run them that way, with lifecycle management, operational integration, and disciplined hygiene, ship faster, respond to incidents faster, and break things less. Teams that treat them as an afterthought pile up flag debt, lose the ability to reason about their own code, and give up one of the best tools they have for managing risk in production.