Technical Implementation: Feature Flags
How A/B tests actually work: feature flags, evaluation vs exposure, and implementation best practices.
From Theory to Practice
You understand what to test and why. Now: how do you actually implement an A/B test? The answer: feature flags.
What Are Feature Flags?
A feature flag (also called feature toggle) is code that controls which version of your product a user sees. It's the mechanism that powers A/B tests by determining which experience each user gets.
// Feature flag implementation example const variant = getFeatureFlag('checkout-redesign', userId); if (variant === 'treatment') { trackExposure('checkout-redesign', 'treatment'); return <NewCheckoutFlow />; } else { trackExposure('checkout-redesign', 'control'); return <CurrentCheckoutFlow />; }
The getFeatureFlag() function checks which variant the user should see, and trackExposure() records when they actually see it. This separation is crucial for accurate analysis.
Feature flags let you deploy code to production without activating it for everyone. You can then selectively enable it for specific users, percentages, or test groups.
Safe Deployments
Deploy code behind flags, roll out gradually
Kill Switches
Turn off features instantly if issues arise
A/B Testing
Assign users to variants, measure results
Evaluation vs. Exposure
This is critical and often misunderstood. Two separate events happen in every experiment:
Evaluation
When it happens
When a user is assigned to a test variant at first encounter with the feature flag.
Example Flow
- →User loads app
- →System checks feature flag
- ✓Assigned to Variant B
Exposure
When it happens
When a user actually sees/interacts with the test experience and the variant code executes.
Example Flow
- →User navigates to checkout
- →New flow renders on screen
- ✓Exposure event fires
Why This Distinction Matters
Analyzing based on evaluation includes users who never saw the test, which dilutes your results.
Wrong: Evaluate at Assignment
Includes users who left before seeing the test
Right: Analyze at Exposure
Only users who actually experienced the test
Key Takeaways
- ✓Feature flags are the technical mechanism that powers A/B tests.
- ✓Evaluation is when a user is assigned to a variant.
- ✓Exposure is when a user actually sees/interacts with the test experience.
- ✓Always analyze based on exposure to avoid dilution and bias.