Feature flags vs deploys: separating release from shipping code
A deploy puts new code on your servers, while a feature flag is a runtime switch that decides whether users see the new behavior.
- Updated Nov 27, 2026
- Markdown
Use flags to ship code dark, roll out gradually, kill a bad feature without a deploy, and remove flags before they pile up.
- An app you deploy regularly
- Access to its configuration or environment
A deploy and a release are different events. A deploy puts new code on your servers. A release is the moment users get the new behavior. A feature flag sits between them: the code ships with the behavior switched off, and you turn it on later, for some users or all, by changing a setting instead of deploying again. That separation makes risky changes easier to roll out and quicker to undo.
How it works#
In code, a flag is a condition around the new behavior:
if (flags.isEnabled("new-checkout", { userId })) {
return renderNewCheckout();
}
return renderOldCheckout();Where the answer comes from is the design choice. It can be an environment variable, a row in a database, a file you reload, or a separate flag service that evaluates rules and returns on or off per user. Anything beyond a simple on or off needs the app to know who the user is, so a percentage can be applied consistently.
Compare this with strategies that move traffic between versions, such as canary releases and blue-green deploys. Those control which version of the code a request hits. Flags control which path runs inside one version. They combine well.
What flags are good for#
Dark launches. Ship the code with the flag off. It runs through your normal deploy and health checks, but users see nothing. You can turn it on for yourself or your team to test on the real server.
Gradual rollout. Enable the feature for a percentage of users, such as a small share first, then more as metrics stay healthy. Use a stable hash of the user ID so the same person keeps the same experience, instead of a random roll on each request.
Kill switches. Wrap risky or expensive features so you can disable them in seconds. Turning a flag off is faster than a rollback and does not undo unrelated changes in the same deploy.
Decoupling teams and schedules. Work can merge to the main branch before it is finished, hidden behind a flag, so branches stay short. Marketing can pick the launch time without asking for a special deploy.
Where environment variables fit#
An environment variable is the simplest flag. In Compose:
services:
app:
image: myapp:1.4.0
environment:
FEATURE_NEW_CHECKOUT: "false"Changing it means editing the file and recreating the container, as described in environment variables and secrets. That gives a short restart gap, and every instance flips together. This is fine for flags that change rarely, such as turning a module on for one environment. It is a poor fit for kill switches or per-user rollout, where you want the change to apply live and to some users only. For those, read the flag from a database table, a small config endpoint or a flag service, and cache it for a few seconds.
Never put secrets in flag values, and do not expose raw flags to the browser if they reveal unreleased plans.
Step 1: Add the flag with a safe default#
Define the flag in one place, with a default of off. If the flag source is unreachable, fall back to the default, so an outage in the flag store does not turn on unfinished work:
const defaults = { "new-checkout": false };
function isEnabled(name, ctx) {
try { return store.get(name, ctx) ?? defaults[name]; }
catch { return defaults[name]; }
}Step 2: Ship dark, then enable in stages#
Deploy with the flag off. Enable it for internal users, then a small percentage, then everyone. After each stage, check error rate and latency, as in monitor uptime simply. Decide before the rollout what result makes you stop.
Step 3: Test both paths#
The flag-off path is your fallback, so it must keep working. Write tests that run each path, at least for the core flow. A flag that is only ever tested in the on position is a hidden bug in your rollback plan. Watch for combinations too: two flags that interact give four paths. Keep flags independent where you can.
Step 4: Clean up#
When a feature is fully rolled out and stable, delete the flag and the old code path. This is the step teams skip. Leftover flags are flag debt: dead branches, confusing logic and tests for paths nobody uses. Give each flag an owner, a purpose and a removal date when you create it, and review the list on a regular schedule.
Check it worked#
Confirm that the new code is deployed but dormant:
docker compose exec app printenv FEATURE_NEW_CHECKOUT
curl -s https://app.example.com/healthThe first prints the current value, false for a dark launch. The second shows the app is up. Then flip the flag for a test user and confirm the behavior changes without a new image tag in docker compose ps. Flip it back and confirm the old behavior returns. If the flag lives in a database, check that a change takes effect within your cache window.
Edge cases and gotchas#
- Flag debt: Every flag is a branch to maintain. Remove flags once a rollout is done.
- Inconsistent users: Random percentages per request make users flip between old and new. Hash the user ID.
- Database changes: A flag does not make a schema change reversible. Use backward compatible migrations so both paths work with the same tables.
- Caching: If responses are cached for all users, a per-user flag may show the wrong version. Vary the cache or skip it for flagged pages.
- Flag service outage: Decide the default when the flag source fails, and test that case.
- Security: A flag that hides a feature does not protect it. Enforce authorization on the server regardless of flags.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Flag change has no effect | App caches the value or needs a restart | Check cache time, recreate the container for env flags |
| Some users see old, some new | Random per request, not per user | Use a stable hash of the user ID |
| New code breaks with flag off | Off path untested | Add tests for both paths, fix the fallback |
| Nobody knows what a flag does | No owner or description | Add metadata, remove if unused |
| Feature visible to wrong users | Flag rules too broad | Review targeting rules, test with sample users |
Quick reference#
| Goal | Tool |
|---|---|
| Hide unfinished work | Dark launch, flag off by default |
| Roll out slowly | Percentage rollout by user hash |
| Stop a bad feature fast | Kill switch flag |
| Per-environment on or off | Environment variable |
| Move traffic between versions | Canary or blue-green deploy |
Related lessons#
- Canary releases explained for moving traffic between versions instead of behavior.
- Rollbacks for when a flag is not enough and the code must go back.
- Environment variables and secrets for the simplest flag source.
- Zero-downtime deploys for shipping the code that carries the flag.
- Monitor uptime simply for the signals you check during a rollout.
Next#
Continue with rollbacks.
Check what you learned
Frequently asked questions
What is the difference between a feature flag and a deploy?
A deploy changes which code runs on your servers. A feature flag changes which behavior that code shows at runtime, so you can release or hide a feature without deploying.
What is a dark launch?
A dark launch ships a feature to production with the flag off or limited to staff, so you can test with real infrastructure before any normal user sees it.
Are environment variables feature flags?
They can act as simple ones, but changing them usually needs a restart or redeploy. Flags read from a database or flag service can change while the app runs.
How many feature flags is too many?
There is no fixed number. The warning sign is flags that nobody can explain or that stay long after the rollout finished, so give each one an owner and a removal date.
Keep going: guides and tutorials
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.
- Roll Back a Failed Docker Deploy Without Downtime Ship a broken release on purpose, watch your users stay on the old version, then roll back with one command. Real commands, real output, self-hosted.
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.