Targeting and Segmentation
What you'll learn: How to control which users see a feature by defining precise audience rules, enabling safe, gradual rollouts without redeploying code.
The Core Idea
Once you have feature flags in place, targeting and segmentation is the mechanism that decides who gets access to a flagged feature. Instead of flipping a flag on or off globally, you define rules based on user attributes (like userId, email, region, or role), percentage rollouts (show to 5% of users), or pre-defined segments (like "beta testers" or "enterprise customers").
This transforms feature flags from simple on/off switches into powerful levers for incremental releases, A/B testing, and risk mitigation.
How It Works
User Attributes
Your flag management system evaluates attributes you provide when checking a flag:
if feature_flag_client.is_enabled("new_checkout", user={"id": "user123", "tier": "premium"}):
show_new_checkout()
Rules in the flag system might target tier == "premium" or user_id in ["user123", "user456"].
Percentage Rollouts
Gradually expose a feature to a percentage of users, typically using deterministic hashing on user ID to keep the experience consistent per user.
Segments
Group users into reusable segments ("internal employees", "beta participants") and target flags at these segments instead of rewriting rules for every flag.
The Analogy
Think of it like a VIP club with a smart doorman. Instead of letting everyone in at once, the doorman checks your membership tier, invitation list, or even randomly selects 10% of arrivals—all based on instructions from management that change dynamically without rebuilding the door.
Key Takeaway:
Targeting and segmentation lets you control feature visibility by user attributes, percentage rollouts, and reusable segments, enabling safe, gradual releases and precise audience control without code changes.