We are still cooking the magic in the way!
Feature Flags
Feature Flags
A feature flag (also called a feature toggle or feature switch) is a conditional branch in code that routes execution based on a runtime configuration value rather than a code deployment. The flag can be flipped on or off without shipping new code. This decouples deployment — pushing new code to servers — from release — making that code active for users. It is the foundational primitive that makes every other progressive-delivery technique practical at scale.
Why the Best Engineering Orgs Live by Flags
At companies like Google, Netflix, Facebook, and Shopify, teams merge to main and deploy to production many times per day. The code for a half-built feature ships behind a flag that is false for everyone. When the feature is ready, the flag is enabled — first for internal employees (dogfood), then 1 % of traffic, then progressively wider. If metrics degrade, the flag is disabled in seconds, avoiding a full rollback. This workflow removes the coupling between code velocity and product risk.
Flag Types
- Release toggles — hide incomplete work in production; removed once the feature is fully shipped.
- Experiment toggles (A/B) — route cohorts to variants for statistical measurement; removed after winner is declared.
- Ops toggles (kill switches) — disable a costly or broken subsystem under load without a deploy (e.g. disable a recommendation engine during peak traffic).
- Permission toggles — enable features for specific user tiers or beta groups permanently (e.g. premium plan features).
Anatomy of a Flag Evaluation
Every flag evaluation follows the same pipeline: the SDK receives a flag key and an evaluation context (user ID, country, plan, device), evaluates targeting rules in order, and returns a variant. The evaluation is synchronous and in-process — no network call during request handling — because the SDK caches a local copy of the flag ruleset from the flag delivery network (Relay Proxy in LaunchDarkly, edge worker in Flagsmith, etc.).
Targeting and User Segmentation
Targeting rules let you control who sees a flag and how much. Rules are evaluated top-to-bottom; the first match wins:
- Individual targeting — specific user IDs (internal team, QA engineers).
- Attribute rules —
country == "US",plan == "enterprise",version >= "2.0". - Percentage rollout — deterministic bucketing on a hash of
userId + flagKeyso the same user always lands in the same bucket (sticky assignment). - Default rule — the fallback for everyone else.
userId + flagKey + salt for percentage rollouts to guarantee consistent user experience.
Implementing a Kill Switch with OpenFeature
OpenFeature is a CNCF standard SDK that abstracts away the flag provider (LaunchDarkly, Flagsmith, Unleash, custom). This lets you swap providers without rewriting application code.
The false default is critical. If the flag service is unreachable, the SDK returns the default — which should always be the safe, known-good path. Never default to true for an unvalidated feature.
Flag Hygiene and Technical Debt
Flags accumulate. A codebase with 200 stale flags has combinatorial explosion in testing surface: 2^200 theoretical states. In practice this causes real incidents — a Salesforce outage in 2021 was partly attributed to an untested combination of legacy flags interacting. Flag debt is as dangerous as code debt.
Enforce these practices on every team:
- Owner + expiry on creation — every flag must have an owner team and a
remove_bydate in the flag metadata. Block PR merges that add a flag without these fields. - Tag flags in code — add a comment
// TODO: remove flag "checkout.new-payment-flow" by 2025-09-01 @payments-teamnext to every flag evaluation. This makes flags searchable in IDEs and static analysis. - Track flag evaluations — export evaluation events to your observability stack. If a flag has had zero evaluations in 30 days, it is a candidate for removal.
- Junk drawer alert — your flag management console should show flags with no evaluations in the last 14 days highlighted in red. Most SaaS platforms (LaunchDarkly, Unleash) support this natively.
Self-Hosting Flags vs SaaS
For regulated industries or air-gapped environments, self-hosted solutions like Unleash (open-source, MIT) or Flagsmith (open-source, AGPL) are production-ready. Deploy with a Relay Proxy in each region to ensure sub-millisecond flag evaluation even if the central server is unreachable.
Flags and CI/CD Integration
Treat flag changes as deployments. When you flip a flag from 0 % to 10 % via the UI, an audit event should flow into your change management system (PagerDuty, Jira, ServiceNow). Wire the flag platform's webhook to your incident management tool so that if an SLO fires within five minutes of a flag change, the on-call responder sees the flag change highlighted in the incident timeline. This dramatically reduces MTTR (mean time to recovery).
git revert, and a diff-based audit log — exactly what you get for Kubernetes manifests with ArgoCD. Flagsmith and Unleash both support configuration-as-code import/export.