Mastering feature flags: control your production features

A feature flag (also called a feature toggle) is a switch in your code that turns a feature on or off, or shows different versions of it, without deploying new code. Feature flags separate deploying code from releasing it, so you can merge work in progress, roll a feature out to a few users first and turn it off in seconds if something breaks.
As software grows, shipping new features safely gets harder. Feature flags are one of the simplest techniques we use at Vinta to evolve systems without overwhelming our teams or our users. This article covers the benefits we get from them, the best practices we learned the hard way, and how flags fit a world where AI writes more of the code and powers more of the features. For how to implement them in Python and which tools to pick, read Hugo Bessa’s guide to feature flags in Python.
Key takeaways
What it is
A switch in the code, set outside it, that turns a feature on or off for everyone or for chosen users.
Why use it
Merge small batches, deploy without releasing, roll out gradually and turn a broken feature off without a rollback.
What it costs
Every flag is a branch in your code and your tests. Name it clearly, give it an owner and remove it once it is fully on.
With AI
Put agent-written changes and model or prompt swaps behind flags, and let agents help remove stale flags, with a human reviewing.
What is a feature flag?
In practical terms, a feature flag is an if-else statement that picks a flow according to the switch’s state:
if flag_is_active('NEW_PRICING_CALCULATION_ENABLED'):
run_new_algorithm()
else:
run_old_algorithm()The flag’s state lives outside the code: in a database table, a settings service or a feature flag platform. Changing it takes effect right away, for everyone or for the users you choose, with no build and no deploy. That simple switch changes how a team integrates, releases and recovers. It also comes with trade-offs you need to plan for, which the rest of this article covers.
Why long-running branches slow teams down
Imagine you’re implementing a dark mode for a site. You branch out to start coding. You need an external library to handle the behaviour, so you add it. Then you start changing every component it affects. You need a database migration to store whether each user’s default mode is dark or light.
Then you dive into refactoring a particularly chaotic function before adding your new code. Finally, you write tests to safeguard your changes. That work goes on for a few days, and when it’s all done, you open your pull request and, oh no, the diff is huge.
If you’ve been coding long enough, you know the drill. Working on a long-running branch feels like building a whole world in a silo. Merging it with other long-running branches is another headache. It’s a mess to review, merge, debug and understand.
The fix is to integrate your code in short cycles, and to do that, you need to break it into small batches. But how do you deliver code that is still a work in progress?
With feature flags, you can deliver in manageable increments. Each merge is small, so reviews and feedback come faster, conflicts are rarer and deploys are calmer.
What are the benefits of feature flags?
Merge small, reviewable batches
Back to the dark mode. First, create the new fields in your models and open a PR. It can be reviewed and merged on its own, independently of the larger change.
Next, wrap the refactor of the chaotic function in a feature flag and ask reviewers to focus on just that change. Once approved, you can merge and deploy it without worry, as long as the flag stays off.
Now you can implement the dark mode one component at a time, each in its own PR. This simplifies reviews and keeps changes manageable. You can also turn finished parts on for a few test users and catch issues early, with a shorter feedback loop (more on that below).
Deploy without releasing
The most immediate benefit of feature flags is separating a deploy from a release. You deploy code that users don’t see yet and turn it on when you’re ready. Development and release then move at their own pace.
Wrapped in a flag, the dark mode can be deployed without exposing it to users. Ongoing work isn’t held back by release dates, which allows continuous delivery and more frequent deploys without disrupting the user experience.
Turn off a broken feature without a rollback
What does “without disrupting the user experience” mean in practice? Suppose something goes wrong during the dark-mode release: the library you added breaks another one, or the UI doesn’t behave as expected.
Without a flag, you revert the pull request, wait for the build and CI, and deploy again, while users live with the bug. With a flag, you turn the feature off, and the old behaviour is back in seconds, with no deploy. This reduces downtime and minimizes the impact on users. A flag kept for exactly this purpose is often called a kill switch.


Roll out gradually and test with real users
With a feature flag, you can turn the dark mode on for a subset of users first, for example 10% of them, or those most likely to welcome the change, and watch how it performs in a controlled setting.
You can target rollouts by percentage or by attribute, such as device type, company size or location. Collecting feedback and spotting issues before the full rollout greatly reduces risk. The same mechanism powers A/B tests; to learn how to run and read them, see how to analyze A/B test results.
The real-time feedback from these rollouts lets your team adjust based on how people actually use the feature, not on assumptions, and makes for a smoother launch.
Put together, the dark mode’s path from first commit to full release looks like this:
Step 1
Implement a first version of the dark mode
- Merge small batches: ship a small piece of the dark mode behind the disabled flag, without waiting for the whole feature.
Step 2
Deploy it to production
- Deploy without releasing: the flag is still off, so the deploy doesn't change what users see.
Step 3
Turn the flag on for specific users
- Test with real users: turn it on for testers or a beta group, collect feedback and catch issues before the full rollout.
Step 4
Turn the flag on for all users
- Reduce the impact: at every step, you can turn the feature off without a new deploy to roll back.
Feature flags reduce risk and enable continuous delivery, but they need care. The rest of this article shares what we learned using them across many projects.
Best practices for naming feature flags
Naming is hard everywhere in software, and flags are no exception. Clear, consistent flag names keep flags understandable and manageable, especially as your project grows:
Name it like this
DASHBOARD_DARKMODE_ENABLED: says what the flag controls and whereNEW_DASHBOARD_ENABLED: a positive name, true when the feature is onTEMP_CHECKOUT_V2_ENABLED: theTEMP_prefix says it will go awayOPS_PAYMENT_GATEWAY_ENABLED: theOPS_prefix marks an infrastructure switch that stays- A new, unique name for every new feature
Not like this
NEW_FEATURE_ENABLED: which feature?DISABLE_NEW_DASHBOARD: a double negative, so “enabled” turns it offIMPROVEMENTS_ENABLED: which improvement, and where?FLAG_1,TEST_FLAG: say nothing about purpose or lifespan- A name reused from an old flag
Reused names deserve a word of their own: if someone changes the wrong flag because an old name now means something else, the result can be a serious incident. And an ambiguous name invites the same kind of mistake, like someone turning off a flag that should stay on because they misread what it controls.
How to keep feature flags from becoming technical debt
As software grows, we keep adding features and flags to control them, and maintaining them can quickly become a nightmare. Keeping each flag’s context in mind takes effort, the risk of bugs rises, and anyone touching flagged code worries about it. Tests have to cover combinations of flags to stay trustworthy.
Two habits helped us most to keep flags from turning into technical debt.
Know each flag’s type and purpose
Tell apart the flags meant for short-term experiments or betas from those meant to stay. If a flag becomes permanent, or you already know it won’t be removed, turn it into a system setting or a user configuration option. Flags add complexity to your code, and permanent complexity hurts maintainability.
Some flags are genuinely long-term, such as a switch that disables an integration with a third-party system gracefully when that system fails. Document and manage them clearly, and make them obvious by name, for example with the OPS_ prefix.
Plan each flag’s removal
Treat feature flags like technical debt and plan their removal as you would legacy code. Once a flag is on for everyone, its other branch is dead code, and too many flags lead to undefined or untested behaviour. Review your flags regularly and remove the outdated, unused or fully enabled ones.
The lifecycle of a release flag
- Created, off
- Deployed dark
- On for testers
- Gradual rollout
- On for everyone
- Removal scheduled
- Flag removed
Removal might mean aligning with the product team on its risks and planning it with the developers. Give every flag an owner: the person who creates it monitors its impact, keeps stakeholders informed and removes it when it’s done.
Track who changed what
Good monitoring and logging let teams follow how flagged features perform, see how users engage with them, and find and fix issues quickly.
Consider recording when each flag was created and who enabled it. That traceability helps you audit changes and understand a flag’s impact over time, especially when many people can change flag settings.
Set up alerts for critical thresholds. If a feature behind a flag causes a spike in error rates, an immediate alert gets someone to act on it fast. Many monitoring tools integrate with feature flag platforms for this.
How to keep behaviour consistent, whatever the flag’s state
Feature flags often control critical system states, which makes consistency harder. In our experience, three scenarios need extra attention.
Protect data integrity
When a feature needs database changes, like new tables or changed structures, plan carefully. Say you must move a simple text field to a richer structure, another table with more data, and you put the change behind a flag so you can ship it in increments.
There is a tricky detail: the two flows behind the flag don’t read the same data. With the flag off, you read the old field; with it on, the new one. How do you keep both flows consistent and switch the flag safely?
Planning means thinking through the code’s behaviour in both flag states. One safe approach is redundancy: write to both the old and the new structures, whatever the flag’s state.
Use the flag only to choose which structure to read from, never which one to write to. The system then behaves the same whether the flag is on or off.
This avoids large data migrations triggered by flag changes, and you can spot discrepancies quickly (a place that still updates only the old field, say) and fix them without disrupting the system. Don’t delete the old data until you’re sure the new flow works: if you need to turn the flag off, the old data must still be there.
Don’t lose user trust
Feature flags should improve the user experience, not complicate it. If users see different behaviour every time they open your product, they get confused, file support requests and lose trust. These strategies helped us:
- Organization-level consistency: if users belong to organizations, turn flags on per organization rather than per user, so colleagues don’t see different behaviour and report it as a bug.
- Communication: use tooltips or notifications to tell users about changes or features under test. It sets expectations and reduces confusion.
- Watch reactions: track which users have a feature on and watch their reactions and the system’s performance. That data drives the decision on the full rollout.
Check the flag when an async task runs
Imagine a flag that controls a new section in the weekly promotions email. The emails go out through a task queue. You turn the flag on and trigger the emails, find an error in the new section and turn the flag off at once. But the emails keep going out with the error, because every task was queued before you turned the flag off.
def send_promotional_emails():
if flag_is_active('SEND_PROMO_EMAIL'):
for user in users:
send_async_notification(user.id)Asynchronous work needs care about where you check the flag. Don’t pass the flag’s state as an argument to the task: changing the flag after the task is queued won’t affect it. Check the flag as late as possible, ideally inside each task, so you can stop the work when you need to:
Do
for user in users:
send_async_notification(user.id)
def send_async_notification(user_id):
if flag_is_active('SEND_PROMO_EMAIL', user_id):
# logic to send emailDon't
send_async_notification(user.id, flag_is_active('SEND_PROMO_EMAIL'))
def send_async_notification(user_id, send_promo_email):
if send_promo_email:
# logic to send emailChecking the flag when the task runs, not when it’s created, greatly reduces the risk of running outdated or faulty tasks.
Feature flags in the age of AI
AI changed two things about shipping software: coding agents write more of the code, and more features call a model. Both make feature flags more useful, not less.
Put agent-written code behind flags
Coding agents produce working changes faster than teams can watch them run in production. Review still matters, but a review can’t show how a change behaves under real traffic. A flag lets you merge an agent’s change dark, turn it on for internal users first and roll it out by percentage, the same way you would a person’s change. If something goes wrong, the kill switch doesn’t depend on how fast anyone can understand the code.
Small, flagged batches also suit agents well: a focused task behind a named flag gives the agent a clear boundary, and gives the reviewer a diff they can actually read.
Treat a model or prompt change as a release
Swapping the model behind a feature, changing a prompt or adding a retrieval step changes behaviour in ways tests rarely catch, because the output isn’t deterministic. Ship those changes behind a flag:
- Roll out by percentage and compare the old and new versions on what matters to you: answer quality, latency and cost per request.
- Keep a kill switch (an
OPS_flag) on every AI feature, so you can turn it off or fall back to the previous model if quality drops, costs spike or the provider has an outage. - Log which variant served each request, with an opaque request ID rather than the user’s input, so you can compare variants without storing what people typed.
Let AI help remove stale flags
Cleaning up flags is the chore teams skip most, and it is a good fit for automation. Uber open-sourced Piranha to remove stale flags with static analysis; today, a coding agent can do the same job across a codebase: find flags that have been fully on for weeks, delete the dead branch and its tests, and open a PR for each flag. A person still reviews each one, especially flags tied to data migrations, where removing the old path can mean losing the way back.
Ship small, release when you’re ready
We’ve used feature flags at Vinta for a long time and have seen how powerful they are, as long as you keep their complexity in check: name them clearly, give each an owner, check them where the work happens and remove them when they’re done.
I hope these insights help you use feature flags to their full potential, so you can take fewer risks and ship more often.


Frequently asked questions
What is a feature flag?
A feature flag is a switch in the code that turns a feature on or off, or picks between versions of it, without deploying new code. Its state lives outside the code, in a database, a settings service or a feature flag platform, so changing it takes effect right away for everyone or for chosen users.
What is the difference between a feature flag and a feature toggle?
None: they are two names for the same technique. You may also see “feature switch” or “feature flipper”. Some teams use “toggle” for the broader practice and “flag” for an individual switch.
What is the difference between deploying and releasing a feature?
Deploying puts the code on production servers; releasing makes the feature visible to users. Feature flags separate the two: you deploy with the flag off, then release by turning it on, for a few users first or for everyone at once.
When should you remove a feature flag?
As soon as a release flag has been on for everyone long enough to trust the new path, usually a few days to a few weeks. From then on, the old branch is dead code. Flags meant to stay, like kill switches, should become documented settings instead.
Are feature flags the same as A/B testing?
No, but A/B tests usually run on feature flags. A flag decides who sees which version; an A/B test adds the measurement and the statistics that tell you which version performs better.
How do you use feature flags with AI and LLM features?
Put each model, prompt or retrieval change behind a flag, roll it out by percentage and compare quality, latency and cost against the current version. Keep a kill switch on every AI feature to turn it off or fall back to the previous model if quality drops or the provider has an outage.
Related articles

Article · 14 min read
Taming irreversibility with feature flags in Python
Feature flags make Python features toggleable, so risky changes are easy to roll back.
14 min read

Article · 12 min read
How to analyze A/B test results Udacity methodology: from hypothesis to implementation
Run and analyze A/B tests with real product examples and a checklist, Udacity style.
12 min read




