Feature flags turn deployment into a two-step process: ship the code, then enable the feature. This separation is powerful when done right and a maintenance nightmare when done wrong.
The Core Value Proposition
Without feature flags, deployment equals release. Ship broken code? Users see it immediately. Need to roll back? Redeploy the previous version. Want to test with 1% of users? Build custom infrastructure.
With feature flags, you decouple these concerns:
- Deploy: Code goes to production, but new features are off
- Release: Flip a flag to enable for some or all users
- Rollback: Flip the flag back off (no deployment needed)
The mental shift: treat deployment as logistics and release as a business decision.
Implementation Patterns
Simple Boolean Flags
Start here. A flag is either on or off:
| |
User-Targeted Flags
Enable for specific users or groups:
| |
The flag service evaluates rules: is this user in the beta group? Are they an employee? Did they opt in?
Percentage Rollouts
Gradually increase exposure:
| |
Sticky evaluation matters. You don’t want users flipping between old and new randomly.
Kill Switches
The underrated use case. Every critical dependency should have a kill switch:
| |
When your notification provider has an outage, flip the flag and gracefully degrade.
Architecture
Client-Side vs Server-Side
Server-side evaluation:
- Flag rules stay on your servers
- User gets final decision, not the rules
- More secure, less flexible for instant updates
Client-side evaluation:
- Rules downloaded to client
- Faster evaluation, no network round-trip
- Rules are visible to users (security consideration)
Most teams use server-side for backend and client-side for frontend, with different security postures for each.
Flag Storage
Options from simple to complex:
| |
For serious use, option 4 wins. The tooling around flag management, audit logs, and percentage rollouts is worth the cost.
Caching Strategy
Flag evaluation happens constantly. Cache aggressively:
| |
30-second TTL is usually fine. Flag changes aren’t instant, but they’re fast enough.
The Flag Lifecycle
Flags are not permanent. They have a lifecycle:
- Create: New feature behind flag, default off
- Test: Enable for internal users, QA
- Rollout: Percentage increase: 1% → 10% → 50% → 100%
- Stable: Flag at 100%, feature proven
- Remove: Delete flag, remove conditional code
Step 5 is where most teams fail. Flags accumulate. Code becomes spaghetti. Nobody knows which flags are still needed.
Flag Hygiene
Enforce cleanup:
| |
Even better: build tooling that alerts when flags are past their removal date.
| |
Testing with Flags
Flags complicate testing. You now have 2^n possible states where n is your flag count.
Test Both Paths
| |
Integration Test the Rollout
| |
Common Mistakes
Flag Coupling
| |
Either make flags independent or create a single flag for the coupled feature.
Flag Sprawl
| |
Rule of thumb: if you have more than 20 active flags, you have a process problem.
Permanent Flags
| |
If it’s been “temporary” for six months, it’s permanent. Remove the flag, keep the code.
Observability
You need to know which flags are evaluated and what values they return:
| |
This lets you:
- See adoption curves during rollout
- Debug “why did this user see the old flow?”
- Catch flags that are never evaluated (dead code)
When to Use Flags
Good use cases:
- Gradual rollouts of risky changes
- A/B testing user-facing features
- Kill switches for external dependencies
- Enabling features for beta users
- Regional or customer-specific features
Probably overkill:
- Internal tooling changes
- Refactors with no user-visible impact
- Bug fixes (just ship them)
- Features that can’t be partially enabled
The Payoff
Done right, feature flags give you:
- Confidence: Ship to production knowing you can turn it off
- Speed: Merge to main without waiting for “release windows”
- Control: Enable for 1% of users and watch metrics before going wide
- Recovery: Rollback in seconds, not minutes
The overhead is real: more conditionals, more testing, more cleanup. But for any team shipping frequently to production, the risk reduction is worth it. 🌍