Feature Flags: The Concept and the Full Value
A feature flag is a conditional branch in the code whose outcome is controlled by an external configuration value — a database record, an environment variable, or a feature flag service. The code for the new feature is written and deployed normally; whether users see it depends on the flag's current value, which can be changed at runtime without a deployment. This creates a clean separation between the technical act of deploying code and the business decision of releasing a feature to users.
- if (featureFlags.newDashboard) { show NewDashboard } else { show OldDashboard }
- The setting comes from a database or external service — not from the code itself
- Can be changed at runtime without a new deployment
- Benefits: confident deploys, instant rollback, gradual rollout, A/B testing
- Cost: code complexity increases — must be managed regularly
- Trunk-based development enabler: developers merge to main daily behind flags — no long-lived branches
- Dark launching: deploy the new code path and collect performance data before showing it to users
- Kill switch: a flag that can instantly disable a problematic feature in production — valuable for payments
Types of Feature Flags: Different Tools for Different Jobs
Not all feature flags serve the same purpose or have the same lifecycle. Treating all flags identically — the same review cadence, the same ownership model, the same expiry expectations — creates the flag hygiene problems that accumulate into significant technical debt. Understanding the different flag types and managing each appropriately prevents this.
- Release toggles: hide an unfinished feature in production — delete after launch
- Experiment toggles: A/B testing — analytics determines which variant performs better
- Ops toggles: disable a heavy feature during peak load — a 'circuit breaker' for features
- Permission toggles: features exclusive to Premium or Enterprise only
- Rule: each flag type has different longevity — don't treat them all the same way
- Release toggle lifespan: days to weeks — delete within one sprint of full rollout
- Experiment toggle lifespan: weeks — delete when the test reaches statistical significance
- Permission toggle lifespan: permanent — tied to the pricing tier, lives as long as the feature
- Ops toggle lifespan: permanent — emergency kill switches should always exist for critical features
Gradual Rollout: Making Canary Releases Systematic
Canary releases expose a new feature to a small percentage of users first, monitor metrics and error rates, then progressively expand the rollout as confidence grows. The 'canary' metaphor references the historical use of canaries in coal mines to detect toxic gas — the small initial user group is the early warning system that catches problems before they affect everyone. A well-instrumented gradual rollout means that even significant bugs affect only a fraction of users and can be reversed in seconds.
- 1% of users: first rollout — monitor error rate and metrics
- 10%: if healthy after 24 hours, expand
- 50% → 100%: stage by stage based on confidence
- Geographic rollout: start with a specific geographic region
- Beta users: users who welcome early experimentation — apply to them first
- Internal users first: deploy to your team's accounts before any external users
- Monitoring gate: automated alerts halt the rollout if error rate increases during expansion
- Rollback in seconds: reverting to 0% for a flag is faster than any code deployment
A/B Testing with Feature Flags: Measuring Real Impact
Feature flags enable controlled A/B tests without any separate testing infrastructure. Users are randomly assigned to variants, the assignment is persisted so each user always sees the same variant, and analytics measure the impact of each variant on the target metric. The key discipline is deciding on the success metric before the test starts — changing metrics after seeing early results is the most common A/B testing mistake.
- Variant A: current design, Variant B: new design — measure conversion
- Random assignment: assign user to variant randomly and persist the decision
- Statistical significance: wait for sufficient data before deciding
- Requirements: adequate sample size (calculator.statsig.com), clear metric defined upfront
- Don't change the metric after the test starts — HiPPO effect
- Minimum detectable effect: define the minimum improvement worth shipping before the test
- Novelty effect: new variants often see a short-term engagement spike — run tests for 2+ weeks
- Segment analysis: aggregate results may mask important differences between user segments
Technical Implementation: Choosing the Right Tool
- To start: a simple Redis flag is sufficient — key = feature_name, value = enabled/config JSON
- SDK in frontend and backend: query the flags service, don't make API calls per request
- Cache flags: check once per minute — not on every request
- Flag evaluation in middleware: evaluate all flags once per request and attach to context
- Type safety: generate TypeScript types from your flag definitions — catch typos at compile time
- Local override: allow developers to override flags via localStorage in dev — speeds development
| Option | Cost | Advantages |
|---|---|---|
| LaunchDarkly | $$ | Managed, powerful, built-in analytics |
| Statsig | $ | Integrated A/B testing + flags |
| Unleash (self-hosted) | Free | Open source, full control |
| Custom build in Redis | Free | Simple, flexible, needs development |
Flag Hygiene: Preventing Technical Debt Accumulation
Flag hygiene is the ongoing practice of cleaning up flags that have served their purpose. Neglected flags accumulate into a form of technical debt that makes code significantly harder to read — every conditional branch around a stale flag is noise that developers must mentally parse. A codebase with 50 unreviewed flags from the past two years has effectively added 50 hidden conditions to every code path they touch.
- Technical debt: old flags accumulate and make code harder to read
- Rule: every flag has an owner and an expiry date
- After a successful 100% rollout: delete the flag and old code within one sprint
- Cleanup sprint: regular review of old flags every month
- Flag catalog: central document listing all flags, their status, and purpose
- Automated alerts: if a flag's expiry date passes without removal, alert the owner
- Static analysis: ESLint rule that warns when a flag has not been reviewed in > 30 days
- PR template: every PR that adds a flag must include the flag's type, owner, and expected lifespan
Feature Flags in Team Workflows: CI/CD Integration
Feature flags are most powerful when they are integrated into the team's development workflow — not as an afterthought applied to risky features, but as the default mechanism for all significant feature development. Trunk-based development combined with feature flags enables teams to merge code to the main branch daily without coordinating large feature branches, dramatically reducing merge conflicts and integration risk.
- Trunk-based development: all developers merge to main daily — flags hide unfinished features
- CI check: test suite runs both flag-on and flag-off code paths — prevents flag bugs in CI
- Deployment pipeline: deploy to staging with flag on, run tests, promote to production with flag off
- Flag review in sprint planning: each sprint closes out flags that were opened in previous sprints
- On-call runbook: document which flags exist as kill switches and what each one disables
- Customer success access: give CS team a flag dashboard to enable beta features for specific customers
- Audit log: all flag changes logged with timestamp, user, and previous value — essential for debugging
