Feature flag dependencies allow you to create a feature flag (called the dependent flag) that's dependent on the state of another flag (called the base flag). This enables sophisticated feature rollout strategies where one flag's activation depends on another flag's value.
When to use flag dependencies
Flag dependencies are useful for:
- Gradual feature rollouts: Enable a complex feature only after its foundational components are active
- Conditional experiments: Run experiments only on users who have specific features enabled
- Safety mechanisms: Ensure critical flags are enabled before activating dependent features
- User segmentation: Target users based on their participation in other flag rollouts
Setting up flag dependencies
You can create flag dependencies through release conditions when creating or editing a feature flag.
Step 1: Create your base flag
First, create the flag that other flags will depend on:
- Navigate to feature flags in your PostHog app
- Click Create feature flag
- Set up your base flag with appropriate release conditions
- Save the flag
Step 2: Create a dependent flag
- Create a new feature flag or edit an existing one
- In the Release conditions section, click Add condition
- Select Feature flags from the property type dropdown
- Choose the flag you want to depend on
- Set the condition (e.g., flag equals
true
or specific variant) - Configure additional conditions and rollout percentage as needed
Step 3: Evaluate the dependent flag
When you evaluate a dependent flag, PostHog will automatically evaluate its chain of dependencies. For example, when evaluating the dependent_flag
flag, PostHog will evaluate the base_flag
flag first and use its value to determine if the dependent_flag
condition is met.
Example: Beta program dependency
Here's a common pattern where you want to enable a new feature only for users in your beta program:
Base flag: beta_program
- 10% rollout to all users
- Returns
true
for beta users,false
for others
Dependent flag: new_dashboard
- Condition:
beta_program
equalstrue
- 100% rollout to users who meet the condition
When the dependent flag is evaluated using any of the evaluation methods, PostHog automatically evaluates the base flag first. This ensures the new dashboard is only shown to beta program participants.
Supported dependency types
Feature flag dependencies support several condition types:
Boolean flags
flag_name
equalstrue
flag_name
equalsfalse
Multi-variant flags
flag_name
equalsspecific_variant
flag_name
equalstrue
(matches any variant)flag_name
equalsfalse
(matches only if flag evaluates tofalse
)
Troubleshooting
Dependent flag not activating
If your dependent flag isn't working as expected:
- Check the base flag: Ensure the flag your dependency relies on is active and returning the expected value
- Verify conditions: Confirm the dependency condition matches the base flag's return value exactly
- Review rollout percentage: Even if conditions are met, the rollout percentage still applies
- Check user properties: Ensure the user meets all conditions, not just the flag dependency