Feature Flag Best Practices: Lessons from Production
Feature flags are deceptively simple. A boolean that shows or hides functionality. But at scale, poor flag management leads to technical debt, bugs, and confusion. Here's what we've learned.
Naming Conventions Matter
A flag named flag1 tells you nothing. Six months later, nobody knows what it does or if it's safe to remove.
Use a Consistent Pattern
[scope]-[feature]-[variant] Examples:
checkout-new-payment-flowapi-rate-limit-v2dashboard-dark-modeexperiment-pricing-page-b
Flag Types and Lifecycles
Not all flags are created equal. Understanding the type helps determine how long it should live.
| Type | Purpose | Lifespan |
|---|---|---|
| Release | Ship new features safely | Days to weeks |
| Experiment | A/B testing | Weeks to months |
| Ops | Kill switches, load shedding | Permanent |
| Permission | Feature entitlements | Permanent |
The Flag Cleanup Problem
Technical debt from stale flags is real. Every flag is a branch in your code. Old flags create confusion, increase cognitive load, and can cause bugs when someone changes the "wrong" path.
Best Practices for Cleanup
- Set expiration dates - When creating a release flag, schedule its removal
- Track flag age - Flags older than 30 days should be reviewed
- Monitor usage - If a flag hasn't been evaluated in weeks, it's probably dead code
- Make removal easy - Include flag location in metadata so cleanup is fast
Targeting Strategies
Start Small, Then Expand
The safest rollout pattern:
- Enable for yourself / the team
- Enable for internal users / dogfooding
- Enable for beta users / early adopters
- Roll out to 1%, 5%, 25%, 50%, 100%
Use Segments, Not Individual Users
Targeting individual user IDs doesn't scale. Instead, define segments:
beta-users- Users who opted into betaenterprise- Customers on enterprise plansinternal- Employees
Anti-Patterns to Avoid
Nested Flags
Flag A controls whether Flag B is checked. Creates impossible-to-debug scenarios.
Flags in Loops
Checking flags inside tight loops adds latency. Evaluate once, store the result.
Too Many Flags
If you have 500 flags, you don't have feature flags. You have configuration. Consider a different approach.
Flags Without Owners
Every flag needs an owner. When the owner leaves, ownership must transfer or the flag must be removed.
Summary
Feature flags are a powerful tool when used correctly:
- Use clear, descriptive names
- Know your flag types and plan for their lifecycle
- Clean up flags aggressively
- Use segments for targeting
- Avoid anti-patterns that create debt