Feature Flags
Feature flags allow you to enable or disable features at runtime without deploying new code. This is essential for testing in production, incremental rollouts, and quick fixes.How Feature Flags Work
Feature flags can be enabled at different scopes:| Scope | Description | Use Case |
|---|---|---|
| Environment | All requests in that environment | Testing in sandbox/staging |
| Customer | All requests for a specific customer | Beta testing with select customers |
| User | Requests from a specific user | Internal testing |
Checking Feature Flags
Backend
Frontend
Request Lifecycle
Feature flags are loaded at the start of every request: TheContextMiddleware determines active flags by checking:
- User making the request
- Customer the request is for
- Environment-level settings
Adding a Feature Flag
1
Add to enum
Update
FeatureFlagNameEnum:2
Add to i18n
Add the flag to
en.json for auditing:3
Generate migration
4
Update migration
Manually add a data migration to create the flag record:
5
Update OpenAPI schema
Using a Feature Flag
Consider the scope needed:- Environment
- Customer
- User
Enable for all users in sandbox/staging first:
- Go to feature flags admin
- Enable for the environment
- Test thoroughly
- Promote to next environment
Removing a Feature Flag
When a feature is fully rolled out:1
Verify rollout
Ensure the flag is enabled across all environments including production.
2
Confirm with product
Get approval that the feature is stable and can be permanent.
3
Remove from code
Remove all
feature_flag_enabled checks and the enum entry.4
Generate migration
Create a migration to remove the flag from the database.
5
Update schema
Models
Best Practices
Keep Flags Short-Lived
Keep Flags Short-Lived
Feature flags should be temporary:
- Add flag when starting feature
- Remove flag after full rollout
- Don’t accumulate old flags
Use Meaningful Names
Use Meaningful Names
Test Both Paths
Test Both Paths
When a flag exists, test:
- Flag enabled behavior
- Flag disabled behavior
- Transition between states
Document Flag Purpose
Document Flag Purpose
Add clear descriptions so anyone can understand:
- What the flag controls
- Why it was added
- When it can be removed