Skip to main content

đźš© Feature Flags

Toggle features without deploying

The Light Switch Analogy

A light switch:

  • Flip on: Light turns on
  • Flip off: Light turns off
  • No rewiring needed

Feature flags are light switches for code. Turn features on or off without deploying new code.

if (featureEnabled("new-checkout")) {
  showNewCheckout();
} else {
  showOldCheckout();
}

Switch in dashboard: ON → OFF
No deployment needed!

Why Feature Flags?

Separating Deploy from Release

TraditionalWith Feature Flags
Deploy code = Feature is liveDeploy code = Feature is deployed (but OFF)
Release when code is readyFlip flag = Feature is live
Rollback = new deploymentRollback = flip flag OFF

Deploy anytime. Release when ready.

Key Benefits

BenefitHow It Helps
Gradual rollouts1% → 10% → 50% → 100% of users
Instant rollbackProblems? Flip to OFF immediately
A/B testing50% see version A, 50% see version B
Kill switchDisable problematic features instantly
TargetingShow to specific users or segments
Ship fasterDeploy incomplete features (hidden)

Types of Feature Flags

TypePurposeLifespanExample
ReleaseControl when feature goes liveShort (remove after rollout)New checkout UI
ExperimentA/B testingMedium (duration of test)Blue vs green button
OpsOperational controlPermanentDisable under high load
PermissionAccess controlPermanentPremium features

Release Flag Example

Week 1: Ship new UI, flag OFF (hidden)
Week 2: Enable for employees only
Week 3: Enable for 10% of users
Week 4: Enable for 100%
Week 5: Remove flag from code

Experiment Flag Example

VariantUsersGoal
A (blue button)50%Measure conversions
B (green button)50%Measure conversions

Winner becomes the default!


How Feature Flags Work

The Flow

1. Code checks flag → "Is 'new-feature' enabled?"
2. Flag service responds → true/false
3. Code executes → Shows feature (or not)
4. Dashboard controls → Toggle without deploy!

Targeting Options

Target TypeExampleUse Case
EveryoneAll usersFull rollout
Percentage10% of usersGradual rollout
User IDuser_123, user_456Beta testers
Attributecountry = "US"Geographic rollout
Combined10% of premium users in EUComplex targeting

Common Use Cases

1. Gradual Rollout

Week% UsersAction
11%Monitor metrics closely
210%Looking good, expand
350%Watching for issues
4100%Full release

Problem at any stage? Turn OFF immediately.

2. Beta Testing

User TypeFlag StateExperience
Beta testers listONSee new feature
Everyone elseOFFSee current experience

No separate beta environment needed!

3. Kill Switch

Third-party API acting up?

if (flags.isEnabled("use-backup-api")) {
  callBackupAPI();  // Failover
} else {
  callMainAPI();    // Normal
}

Toggle in seconds, no deploy needed.

4. A/B Testing

MetricVariant AVariant BWinner
Conversion rate3.2%4.1%B
Cart abandonment45%38%B

Data-driven decisions!


Feature Flag Platforms

ToolTypeBest For
LaunchDarklyEnterprise SaaSComplex targeting, scale
SplitEnterprise SaaSExperimentation focus
FlagsmithOpen sourceSelf-hosted control
UnleashOpen sourceSelf-hosted, feature-rich
ConfigCatSimple SaaSSmall teams, quick setup

Build vs Buy Decision

NeedsRecommendation
Simple on/off for a few featuresBuild (if/else with database)
Targeting, experiments, analyticsBuy (LaunchDarkly, Split)
Enterprise scale, complianceDefinitely buy

Feature Flag Lifecycle

CREATE →  DEVELOP →  TEST →  BETA →  ROLLOUT →  RELEASE →  CLEANUP
  ↓          ↓        ↓       ↓         ↓          ↓          ↓
Add flag   Devs     Enable  Enable   1%→10%→    100%      Remove
(default   can      for     for      50%→100%   rollout   flag from
 OFF)      enable   QA      beta                           code
           locally  env     users

Cleanup is CRITICAL - old flags pile up!


Best Practices

1. Clean Up Old Flags

ProblemSolution
100 old flags = confusing messRemove flags after full rollout
"Is this flag still needed?"Set cleanup dates when creating
Dead code pathsDelete both flag and feature code

2. Name Flags Clearly

❌ Bad✅ Good
flag_123enable_new_checkout_ui
test_featureexperiment_green_signup_button

Include what it controls and its purpose.

3. Default to Conservative Behavior

ScenarioDefault Behavior
Flag evaluation failsReturn OFF (existing behavior)
Flag service is downUse cached value or OFF
New featureOFF until explicitly turned ON

4. Log Flag Evaluations

Log every evaluation for debugging:

  • User ID
  • Flag name
  • Result (on/off)
  • Timestamp

Essential for "Why did user X see Y?"


Common Mistakes

1. Not Removing Flags

Problem: Old flags pile up, code becomes spaghetti Solution: Schedule cleanup as part of feature completion

2. Flag Dependencies

Flag AFlag B (requires A)Result
ONONWorks
ONOFFWorks
OFFONDoesn't work

Document dependencies. Test combinations.

3. Testing Only One Path

Make sure to test both:

  • Feature ON path
  • Feature OFF path

Both must work correctly!

4. Using Flags for Config

❌ Feature Flag✅ Configuration
DATABASE_URLEnvironment variable
API_TIMEOUT=30Config file
enable_new_uiFeature flag âś…

Flags are for temporary feature control, not permanent settings.


FAQ

Q: Feature flags vs environment variables?

AspectEnv VarsFeature Flags
When setDeploy timeAnytime
ChangeRequires restartInstant
TargetingPer environmentPer user

Q: Do feature flags slow down my app?

Good platforms cache locally. Typical impact is microseconds - negligible.

Q: How do I handle flags in tests?

Set flags explicitly in tests. Don't depend on production flag state.

Q: Client-side or server-side?

Server-sideClient-side
More controlFaster
Less exposedNeeds SDK
Can hide flag logicFlag visible in code

Summary

Feature flags decouple deployment from release, enabling controlled rollouts and instant rollback.

Key Takeaways:

  • Toggle features without deploying
  • Gradual rollouts reduce risk
  • Instant rollback in emergencies
  • A/B testing built-in
  • Target specific users/segments
  • Clean up flags after release!
  • Default to OFF for safety

Feature flags give you a "kill switch" for every feature!

Leave a Comment

Comments (0)

Be the first to comment on this concept.

Comments are approved automatically.