In short
A feature flag is a switch in your code that controls who sees a feature, without a new deployment. Flags help when you need to roll out gradually, separate deployment from release, turn off something risky quickly, or test variations. They're unnecessary for small, safe changes. Every temporary flag needs an owner and a removal date, as forgotten flags turn into serious technical debt.
What they are
In the simplest form, a feature flag is an if statement:
if (flags.isEnabled("new-checkout", user)) {
return renderNewCheckout();
}
return renderOldCheckout();
The value comes from a configuration, a database or a flag service, so you can change it without shipping new code. That splits two things that are normally joined: deploying code to production, and releasing a feature to users.
When they help
Gradual rollouts. Release to staff, then 1% of users, then 10%, and so on. If error rates climb, you've limited the damage. See how to set up error tracking to spot this.
A kill switch. If a feature causes trouble, turn it off in seconds, rather than deploying a fix or a rollback under pressure. It's particularly valuable for features that rely on a third party, such as an AI provider.
Merging unfinished work. Long-lived branches are painful. With a flag, developers can merge unfinished code that stays switched off. This is especially useful with agents producing lots of code.
Timed launches. Marketing wants a feature live at 9am on launch day? Flip the switch, and don't deploy.
Testing variations. Flags are the mechanism behind most A/B tests. See how long an A/B test should run.
Testing in production. Staff can try a feature on real infrastructure before customers see it.
Plan differences. Some flags control what different customers can access, which is a slightly different job.
The four main types
Martin Fowler's well-known article describes these categories:
| Type | Purpose | How long it lives |
|---|---|---|
| Release toggle | Hide unfinished or unreleased work | Days to weeks |
| Experiment toggle | A/B tests | Weeks |
| Ops toggle | Kill switches, shedding load | Some are long-term |
| Permission toggle | Access by plan or role | Long-term |
This distinction matters, as they need different rules. A release flag that's still there a year later is a mistake. A permission flag may well be permanent.
When you don't need one
- A small, low-risk change that's easy to roll back
- A copy or styling tweak
- An early product with few users, where you can simply deploy
- A bug fix that everybody should get
- Database changes, which flags can't easily undo
A flag isn't free. It adds a code path to test, and something else to understand. Don't add one out of habit.
The hidden costs
More paths to test. Ten independent flags can create over 1,000 combinations. You can't test them all, so test the important ones, and keep flags independent.
Technical debt. Old flags leave dead code, and nobody remembers what they did. See the real cost of technical debt. There's a famous cautionary tale: Knight Capital lost more than $460 million in 2012 after a deployment error reactivated old code through a repurposed flag, according to the SEC's findings.
Flicker. Client-side flags that load late can show the old version briefly, then swap.
Performance. Fetching flags adds requests, unless they're cached well.
Access mistakes. A flag isn't a security control on its own. Sensitive features still need proper permission checks on the server.
How to start
Option 1: config or environment variables. They're free and simple, but they usually need a redeploy or restart, and offer no per-user targeting. That's fine for a kill switch on a small app.
Option 2: a database table. You get a small admin screen and per-user rules. Beware of building your own big flag system by accident.
Option 3: a flag service or library. Options include LaunchDarkly, Statsig, PostHog, Flagsmith, Unleash and GrowthBook, several of which are open source. OpenFeature is a vendor-neutral standard that reduces lock-in. Vercel, among others, also has flag features. These are worth it once you have several teams or frequent rollouts.
Check prices against your usage, as some services charge per seat, and others by events or users.
Good practice
- Give flags clear names.
new-checkout-2026is better thantest3. - Record an owner and a removal date when you create a flag.
- Add a ticket to remove it at the same time.
- Default safely. If the flag service is down, then what happens? Usually you'd want the existing behaviour.
- Evaluate flags on the server where possible, to avoid flicker and exposed logic.
- Keep the check in one place, rather than scattered across dozens of files.
- Log changes, so that when something breaks you can see who flipped what.
- Restrict who can change production flags.
- Include both paths in your tests, for the flags that matter. See what you should actually test.
- Review regularly. Once a month, list the flags and remove anything that's fully rolled out.
Removing a flag
Once a feature is fully released and stable, delete the flag, the old code path and related tests. Many teams track “stale flags” automatically. This is an ideal task for a coding agent, as it's mechanical and easy to verify, although you should still review the diff.
Flags and databases
Flags work best with changes that are easy to reverse. If a new feature requires a database change, use an expand-and-contract approach, so that both old and new code can run together. See how to write a safe database migration.
Do you need them yet?
If you deploy small changes with a quick rollback and have a few users, then probably not. Add your first flag when a release genuinely worries you. Keep it simple, remove it afterwards, and only adopt a service when the manual approach starts to hurt.
If you'd like help building a safer release process, book a call.
Common questions
What is a feature flag?
It's a switch in your code which controls whether a feature is active, for everyone or for particular users, without deploying new code. Teams use them for gradual rollouts, kill switches, A/B tests and merging unfinished work safely.
When should you use feature flags?
Use them when a release is risky, when you want a gradual rollout, when you need a way to turn something off quickly, or when you're running experiments. For small, safe changes that are easy to roll back, you probably don't need one.
What is the downside of feature flags?
They add code paths to test, and they can leave dead code behind if nobody removes them. Too many interacting flags make behaviour hard to predict. Give temporary flags an owner and a removal date, and clean them up regularly.
Do I need a tool like LaunchDarkly for feature flags?
Not at first. A config value or simple database table may be enough for a small app. Paid or open-source services become worthwhile once you need targeting, audit logs, and several teams making changes, or frequent rollouts.