A feature flag is a runtime switch that decides whether a code path runs. With flags, you can deploy code that is turned off, turn it on for a few users, watch what happens, and turn it off instantly if something goes wrong, without a new deploy.

Kinds of flags

KindPurposeLifetime
Release flagHide unfinished or risky featuresDays to weeks
Kill switchTurn off a feature or dependency in an emergencyLong-lived
Experiment flagA/B testsLength of the experiment
Permission flagFeatures by plan or customerLong-lived (often better as entitlements)
Operational flagTune behaviour (cache on/off, batch size)Long-lived

Gradual rollout

Turn a release flag on for internal users first, then 1%, 10%, 50% and 100% of users, watching metrics at each step. Use a stable hash of the user or account ID so each user consistently sees the same variant.

function isEnabled(flag: Flag, userId: string): boolean {
  if (!flag.enabled) return false;
  if (flag.allowList.includes(userId)) return true;
  const bucket = parseInt(sha256(`${flag.key}:${userId}`).slice(0, 8), 16) % 100;
  return bucket < flag.rolloutPercent;
}

Kill switches for dependencies

Wrap calls to non-essential dependencies (recommendations, reviews, personalisation, a new search backend) in a kill switch. During an incident, turning one off is faster and safer than a rollback, and the rest of the product keeps working. Combine with circuit breakers for automatic protection.

Monitoring a flag change

Treat turning on a flag like a deploy:

  • Record flag changes as events or markers, with who changed what and when.
  • Tag telemetry with the variant where it matters (a span attribute such as feature.new_checkout=true), so you can compare error rate and latency between users with and without the feature.
  • Watch business metrics for the affected journey.
  • Define in advance what makes you turn it off.

Worked example

A team built a new search backend behind a flag. They enabled it for staff, then 5% of users. Traces tagged with search.backend=new showed p95 latency of 180 ms against 240 ms for the old backend, but the error rate was 0.8% against 0.1%. Logs linked to the failing traces showed timeouts for queries with special characters. They paused at 5%, fixed the query escaping, and completed the rollout two days later without any user-visible incident.

Flag hygiene

Flags are technical debt with a timer:

  • Give each flag an owner and an expiry date.
  • Remove release flags within a few weeks of reaching 100%.
  • Limit the number of flags active in one code path; combinations multiply test cases.
  • Never use flags to hide secrets or security controls.
  • Keep flag evaluation fast and resilient: cache the configuration locally and choose a safe default if the flag service is unavailable.

Flags and incidents

Add "check recent flag changes" to your incident response plan next to "check recent deploys". A flag flipped an hour ago is as likely a cause as a deploy. VitalRix's AI assistant lists recent deploys and configuration changes from the audit trail on each incident; recording flag changes as events or deploy markers makes them visible in the same place.

Checklist

  1. Release flags for risky features, kill switches for non-essential dependencies.
  2. Gradual rollout with stable hashing.
  3. Flag changes recorded and visible next to metrics.
  4. Variant tagged on telemetry where comparison matters.
  5. Owners and expiry dates; old flags removed.
  6. Safe defaults if flag evaluation fails.

Common mistakes

  • Flags left at 100% for months, with both code paths still in the codebase.
  • Nested flags whose combinations nobody has tested.
  • Changing flags without a record, so nobody connects a flag flip to the incident that followed.
  • Evaluating flags with a network call on every request, making the flag service a dependency of everything.
  • Flags with different defaults in different environments, so staging tests a path production never runs.

Where to keep flag changes visible

Flag changes belong in the same place as deploys and configuration changes, so an engineer looking at an incident sees them on the timeline. Record them as events from your flag service, or as markers on your dashboards. See what is APM for how deploy markers help diagnosis, and canary deployment for comparing variants safely.

Are feature flags the same as canary releases?

They overlap. A canary routes traffic between versions; a flag switches behaviour inside one version. Both expose changes gradually.

Do feature flags slow down my app?

Not if evaluated locally from cached configuration. Avoid a network call per evaluation.

How many flags is too many?

When nobody knows what they do. Track owners and expiry dates, and remove release flags soon after full rollout.

Try VitalRix free

Uptime monitoring, APM, logs, real user monitoring and status pages in one place. No credit card needed.