Feature Flags Explained: Ship Faster Without Breaking Production

Feature Flags Explained: Ship Faster Without Breaking Production

A feature flag is a switch in your code that turns a feature on or off without a new deploy. You merge the code, keep it dark, then flip it on for 1% of users, then 10%, then everyone. If something breaks, you flip it off in seconds instead of rolling back a release. This guide covers feature flags explained in plain terms: the four types, gradual rollouts, safe production testing, and cleanup.

Feature Flags Explained: The Four Types You Will Actually Use

Four types cover nearly every case.

Release flags hide unfinished work. You merge a half-built page behind a flag and turn it on only when it is ready. The flag dies once the feature is fully live.

Experiment flags split users into groups so you can compare two versions. Show the new onboarding flow to half of new signups, measure which group finishes setup, and keep the flag only as long as the experiment runs.

Ops flags control system behavior. A flag can switch to a fallback payment provider or turn off an expensive job during peak traffic. Ops flags are often permanent, and they are the ones you reach for at 2 a.m.

Permission flags gate features by plan or user type. A team on the Pro plan sees the export button; a free plan does not. These flags tend to live a long time, because the rule they encode is part of the product. Record the type when you create a flag, so a release flag never gets confused with a permission flag.

How a Flag Works in Code

At its simplest, a flag is an if statement that reads its value from outside the code: a config file, a database, or a flag service such as LaunchDarkly or Flagsmith.

if flags.isEnabled("new-checkout", user) {
  renderNewCheckout(user);
} else {
  renderOldCheckout(user);
}

The second argument matters. A flag that only knows on and off is a blunt tool. A flag that can answer per user, per team, or per percentage lets you roll out gradually, run experiments, and give early access to beta testers without a separate build.

Keep the flag check close to the feature it guards. One check at the entry point, then normal code underneath, keeps cleanup cheap.

Gradual Rollout Feature Flags: From 1% to 100%

A gradual rollout is the main reason teams adopt flags. You turn a feature on for a small slice of traffic, watch error rates and latency, then widen the slice. A problem that hits 1% of users is a bug report. The same problem at 100% is an incident.

A common schedule is 1%, then 5%, 25%, 50%, then 100%, with a pause at each step for real traffic to pass through: an hour per step for a low-traffic tool, a day for a payment flow.

Roll out by a stable key, usually the user ID or account ID, so the same user sees the same version on every visit. Rolling out by random request means a user can flip between the old and new checkout on every page load, which confuses users and ruins experiment data.

Decide in advance what would make you stop: pick two metrics, such as error rate and checkout completion, and a threshold that triggers turning the flag off. A gradual rollout is not the same as a canary deploy, though the two work well together. If you want to compare the two release strategies, read our guide to blue-green vs canary deployments before you pick one.

Testing in Production Without Breaking It

Flags let you test in production, which sounds reckless until you see the alternative: testing only in staging, where traffic patterns, data volume, and third-party services never match the real thing. A flag gives you production testing with a kill switch.

Start with internal users only: turn the flag on for your own team, let them use it on real data for a few days, and fix what they find before any customer sees it.

Next, open the flag to a small group of real users, ideally beta volunteers. Watch logs and metrics, not just complaints: a silent failure, such as a background job that stops writing records, will not generate support tickets, but it will show up in your dashboards. Tag logs and metrics with the flag state so you can compare users who see the new feature against those who do not. When the risky part of a release sits behind a flag, the deploy itself becomes boring, and boring deploys are the goal. Our guide on zero-downtime deployments on Kubernetes covers the infrastructure side of that same idea.

Feature Flag Best Practices for Naming and Ownership

Flags fail quietly when nobody owns them. A flag created for a two-week experiment in 2023 can still sit in the code in 2026, checked on every request, with nobody sure what it does. Naming and ownership rules stop that rot before it starts.

Use names that say what the flag does and who it is for. new-checkout-2026-q4 beats feature-123. Include the team or area, such as billing or search, so anyone reading the code knows who to ask. Avoid names that describe a state, like temp-fix, because temporary names have a habit of becoming permanent.

Every flag needs an owner and an expiry date. The owner is one person, not a team, and the expiry date is the day someone has to decide: delete the flag, extend it with a reason, or convert it into a permanent permission flag. Put the owner and expiry in the flag description, not in a chat message that will scroll away.

Keep flag checks out of hot loops. A check that hits a remote service on every request adds latency, so cache values for 30 to 60 seconds and evaluate once per request. Treat flag changes like code changes: a flip from 10% to 100% deserves the same review and audit trail as a deploy.

Feature Flag Cleanup: Removing Stale Flags Before They Rot

Feature flag cleanup is the chore every team postpones and every team regrets postponing. A stale flag is one whose rollout finished long ago but whose code is still in the codebase, branching on a condition that is now always true or always false. Each one adds a path tests must cover, that new developers must understand, and that can hide a bug.

Schedule cleanup as part of the rollout, not after it. When you create a release flag, open the cleanup ticket at the same time, due the week after full rollout, naming the files with the flag check and which branch stays. A ticket written by the flag’s creator takes five minutes. The same ticket written a year later takes a day of digging.

Removal is simple: delete the flag from the flag service, delete the dead branch, and keep the branch that won. Then deploy and watch. It is still a code change, so it goes through normal review.

Run a stale-flag audit once a quarter: list every flag, its owner, its last change, and its rollout percentage, and put any release or experiment flag older than three months with no activity on the cleanup list. Cleanup also matters for your rollback story: if a deploy goes wrong and the flag cannot save you, you still need a way back, which is why it helps to know how to roll back a broken deployment with Docker tags alongside your flag setup.

When Not to Use Feature Flags

Flags are not free. Every flag is a branch in the code, a line in the flag service, and a future cleanup ticket. Use them where the safety is worth the cost, and skip them where it is not.

Do not use a flag for a small, low-risk change such as fixing a typo, changing a button label, or updating copy. The cost of creating, naming, owning, and later removing the flag is higher than the risk of shipping the change directly.

Do not use flags for database migrations. A flag cannot run a migration in two directions, and flipping it back will not undo rows the new code already wrote. Migrations need a backward-compatible schema change first, then the code change.

Do not use long-lived flags for things that should be settings. If users can turn something on and off themselves, that is a user preference, stored with the user, not a flag in your deploy pipeline. Flags control when code runs, while versions control what code ships. Our explainer on semantic versioning, and when to bump major, minor, or patch pairs well with a flag-based release flow. That is feature flags explained in practice: start with one flag on your next risky change: a clear name, one owner, a rollout plan of 1% to 100%, and a cleanup ticket dated for the week after launch.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.