How it works
Feature flags wrap new code behind a conditional check:Creating a flag
Create flags from the feature flags page:Configure the flag
- Key: Unique identifier (e.g.,
new-checkout-flow) - Name: Human-readable name
- Description: What this flag controls
Set rollout rules
Choose your rollout strategy:
- Roll out to everyone (100%)
- Roll out to a percentage (e.g., 10% of users)
- Target specific users by properties
- Use multiple conditions with AND/OR logic
Rollout strategies
- Percentage rollout
- Property targeting
- Multiple groups
Release to a percentage of users:
- Set rollout to 10% initially
- Monitor metrics for issues
- Increase to 25%, then 50%, then 100%
- Roll back to 0% instantly if problems arise
PostHog uses consistent hashing. The same users always see the feature at each percentage level.
Using flags in code
Check flags across platforms:- JavaScript
- React
- Python
- Node.js
Multivariate flags
Return different values instead of just true/false:Bootstrapping flags
Avoid flicker by loading flags on the server:Local evaluation
Evaluate flags on your server for faster performance:Early access features
Let users opt in to beta features:Create an early access feature
- Go to Feature flags → Early access
- Click New early access feature
- Link to an existing feature flag
- Add a name and description
Common workflows
Safe deployment
Wrap new code in a flag set to 0%. Deploy to production with feature disabled. Test internally by enabling for your team, then gradually roll out.
Kill switch
If a feature causes issues, set rollout to 0% instantly. No code deployment needed. Fix the issue and re-enable when ready.
Beta program
Create a flag targeting users with
beta_user = true. Let users opt into beta features via your settings page.Sunsetting features
Before removing code, set flag to 0% for a week. If no complaints, the feature wasn’t being used. Safe to delete.
Flag analytics
Track flag performance:- Usage dashboard: See which flags are active and their rollout percentage
- Event tracking: PostHog automatically tracks
$feature_flag_calledevents - Correlation analysis: See if flag variants correlate with conversion or retention
Create insights filtering by
$feature_flag property to compare metrics across flag states.Best practices
Use flags for all new features
Use flags for all new features
Make feature flags your default deployment strategy. The ability to roll back instantly is worth the small code overhead.
Clean up old flags
Clean up old flags
After a feature is fully rolled out and stable, remove the flag from code. Keep your codebase clean of unused conditionals.
Name flags clearly
Name flags clearly
Use descriptive names like
new-checkout-flow not flag-123. Your future self will thank you.Test flag conditions
Test flag conditions
Before rolling out, test flag logic by setting your user properties to match your targeting rules. Verify the flag returns the expected value.
Document flag purpose
Document flag purpose
Use the description field to explain what the flag controls and when it can be removed. Helps with cleanup later.