Feature Flags — decouple deploy from release, decouple release from drama
A feature flag is a runtime conditional that decides whether a code path is active. Add flags and you can deploy a hundred times a day while still releasing on Tuesday at noon to 5% of Germany. Combined with canary deploys and observability, flags become the progressive-delivery primitive — the smallest unit of risk you can ship.
6.1 · Why flags
Definition. A feature flag (a.k.a. feature toggle, feature gate) is a configuration value evaluated at runtime that determines whether a branch of code executes or which variant is served. The mechanism is trivial — an if — but the implications restructure the release process.
Deploy ≠ Release. Code merges and ships dark; you flip the flag when you (or marketing, or compliance) are ready.
Kill switch. A regression caught in production is disabled in seconds, no rollback artefact required.
Experiment platform. A/B/n tests run on the same plumbing that gates releases.
Trunk-based enabler. Long-lived feature branches become unnecessary — a half-built feature ships behind a flag set to off.
Permission & entitlement. Plan tiers, beta access, geo restrictions all become flag rules instead of bespoke code.
The Forsgren-style payoff: teams with mature flagging consistently report higher deployment frequency and lower change-failure rate (DORA 2023, Accelerate State of DevOps). Flags do not cause elite performance, but they remove the most common reason teams batch changes.
6.2 · The flag taxonomy
Type
Purpose
Lifetime
Owner
Release flag
Hide an in-progress feature until ready; ramp to 100% then remove.
Days–weeks
Feature team.
Experiment flag
Serve variants to measure causal impact on a metric.
Emergency disable for a subsystem (payments, recommendations).
Permanent, rarely flipped
SRE.
Type confusion is the #1 flag failure mode. A release flag that lingers becomes an operational flag becomes dead code. Tag the type in your platform; enforce expiry on release flags.
Definition. A targeting rule maps a request (the evaluation context: user id, attributes, segment) to a variation of a flag. Rules evaluate in order; the first match wins; otherwise the default applies.
Rule shape
Example
User list
userId in ["alice","bob"] → true
Segment
segment = "Beta-Customers" → true
Attribute match
plan = "enterprise" AND country in ["DE","FR"]
Percentage rollout
10% of users (sticky via hash of userId)
Prerequisite
Flag new-checkout only evaluates if flag checkout-rewrite is on
Definition. An experiment uses random assignment of users to variants and a statistical procedure to estimate the causal effect of a change on one or more metrics of interest (the primary metric) while monitoring guardrail metrics (revenue, latency, errors).
Method
Trade-offs
Used by
Frequentist fixed-horizon (t-test, χ²)
Simple, classic; needs pre-declared sample size; no peeking.
Most platforms.
Sequential testing (mSPRT, Always-Valid CIs)
Safe to peek; stop early on strong signal; conservative power.
Statsig, Optimizely Stats Engine.
Bayesian
Posterior probability "B beats A"; intuitive; needs priors.
VWO, GrowthBook.
CUPED (Controlled-Experiment Using Pre-Experiment Data)
For marketplace or ranking experiments where SUTVA violates.
DoorDash, Uber, Lyft.
Guardrails are mandatory. Even a conversion-positive variant gets rolled back if p99 latency or error rate breach.
Sample ratio mismatch (SRM) — if 50/50 split yields 52/48, the experiment is biased; halt and investigate.
Novelty effect & primacy effect — early days of a test over- or under-state impact; require a soak.
6.6 · OpenFeature — the CNCF standard
Definition.OpenFeature is the vendor-neutral specification and SDK set for feature flagging, donated to the CNCF in 2022 and promoted to Incubating in 2023. It defines an Evaluation API, a Provider interface (the adapter to a backend), Hooks (telemetry, validation), and an Evaluation Context.
flagd — OpenFeature reference daemon; reads flag definitions from files, Kubernetes CRDs, or remote sources.
Provider switching is one line. Migrate vendors without touching call sites.
Hooks standardise telemetry (OpenTelemetry spans on each evaluation), validation, and logging across vendors.
6.7 · Progressive delivery
Definition.Progressive delivery (term coined by James Governor of RedMonk, 2018) combines feature flags + canary deployments + observability so that releases are gradual, measured, and reversible. The flag controls audience; the deployment controls binary; the metrics control progression.
Step
Deploy state
Flag state
Signal watched
Merge
Image built
Off everywhere
CI green
Deploy to prod
Pods running v2
Off (dark)
Startup probes
Internal dogfood
v2 100% in prod
On for staff segment
Error logs, perf
1% canary release
v2 100% in prod
On for 1% of users
SLO, conversion
50% → 100%
v2 100% in prod
Ramped via analysis
Guardrails, primary metric
Cleanup
v2 stable
Flag removed in next PR
Code refs zero
Argo Rollouts + LaunchDarkly integration — AnalysisRun can flip a flag based on Prometheus / Datadog metrics.
Flagger + Datadog — Mann-Whitney metric checks tied to flag ramps.
Statsig Auto-rollback — pulse-monitors guardrails; auto-disables the experiment on regression.
6.8 · Flag hygiene
Flag debt is the cholesterol of your codebase. Old release flags clutter conditionals, multiply test matrices, and hide dead branches. The 2023 Statsig benchmark found 35% of release flags outlive their useful purpose by a year or more.
Every flag has an owner (team + person) and an expiry date stored in the platform.
Stale-flag PRs are automated — Flag-Cleaner (Uber, OSS 2023), LaunchDarkly Code References + Stale Flags, Statsig Cleanup Bot.
One-way doors get tagged — flags whose removal would be a regression (operational, entitlement) are marked permanent.
Tests cover both variants while a release flag is live; remove the off-branch tests when you remove the flag.
SDK downloads the full ruleset; evaluates in-process.
µs
Slight memory + initial fetch; no per-call network.
Remote evaluation
Every call → HTTPS to the platform; identity stays server-side.
5–50 ms
Higher cost & latency; better for PII-sensitive rules.
Edge evaluation
Ruleset replicated to CDN edge (Vercel Edge Config, Cloudflare KV).
< 1 ms
Eventual consistency on the order of seconds.
Streaming updates (SSE / WebSocket)
Push rule changes to SDKs as they happen.
Seconds to converge
Persistent connection per SDK instance.
Polling updates
SDK fetches the ruleset on an interval (default 30–60 s).
Up to interval
Simpler; higher tail latency on flag flips.
Offline cache
Last-known ruleset persisted to disk so cold starts still serve.
—
Required for safety; never block app startup on the flag service.
Never let your flag platform be a hard dependency. If LaunchDarkly is down, every request should default to the safe variant from local cache — not 500. Test this with a chaos drill.
6.10 · Anti-patterns
Anti-pattern
Symptom
Remedy
Flag debt
500 flags, 80% should be deleted
Owners + expiry + automated cleanup PRs.
Deeply nested flags
if(a) if(b) if(c) ...
Refactor to one variant per surface; prerequisites in the platform, not code.
Flag-as-config
Cron interval stored in flag
Use a config service (AppConfig, Consul). Flags are for behaviour, not tuning.
Flag flips without rollout plan
"It worked in staging" → 100% on Friday
Always ramp via percentage rollout + watch dashboard.
Server flags shipped to clients
Mobile apps see flags that leak roadmap
Use client SDK with server-side variant only; obscure flag names.
No fallback default
Service crashes when platform is unreachable
Always pass a safe default; cache to disk.
One mega-flag controlling 12 features
Cannot roll back one regression without disabling others
One flag per shippable behaviour.
Cross-references
Ch 02 — trunk-based development depends on flags to keep mainline shippable.