Feature Flags Guidelines
Feature flags enable controlled rollout of new features, instant rollback capability, and decoupled deployment from feature activation. Every new feature must implement feature flags as part of our systematic approach to reducing production bugs.
When to Use Feature Flagsโ
Required for all new features to enable:
- Risk mitigation: Instant disable without deployment
- Gradual rollouts: Test with subset of users first
- A/B testing: Compare feature performance
- Decoupled deployment: Ship code without activating features
Implementation Patternsโ
React Applicationsโ
Use @ttoss/react-feature-flags
for React applications:
import { FeatureFlag } from '@ttoss/react-feature-flags';
const MyComponent = () => {
return (
<FeatureFlag name="new-checkout-flow" fallback={null}>
<NewCheckoutComponent />
</FeatureFlag>
);
};
Backend Servicesโ
For backend implementations, use environment variables or configuration:
const isFeatureEnabled = (featureName: string): boolean => {
return process.env[`FEATURE_${featureName.toUpperCase()}`] === 'true';
};
if (isFeatureEnabled('new_payment_processor')) {
// New implementation
} else {
// Existing implementation
}
Best Practicesโ
Unique Entrypointsโ
Ensure all feature dependencies are contained within the feature flag boundary:
// โ
Correct: All dependencies inside feature flag
<FeatureFlag name="my-feature" fallback={null}>
<MyNewComponent />
</FeatureFlag>;
// โ Incorrect: Dependencies outside feature flag
const data = useMyNewComponentHook(); // Executes even when disabled
<FeatureFlag name="my-feature" fallback={null}>
<MyNewComponent data={data} />
</FeatureFlag>;
Naming Conventionsโ
- Use descriptive, kebab-case names:
new-checkout-flow
- Include scope when needed:
admin-advanced-reporting
- Avoid generic names:
feature-a
,test-feature
Lifecycle Managementโ
- Development: Create flag, implement feature
- Staging: Validate with flag enabled
- Production: Gradual rollout (5% โ 25% โ 50% โ 100%)
- Cleanup: Remove flag after stable period (typically 2 weeks)
Integration with Development Processโ
Pull Request Requirementsโ
Every PR with new features must:
- Include feature flag implementation
- Document flag name and purpose
- Provide rollback plan via flag disable
Code Review Checklistโ
- Feature flag implemented for new functionality
- Unique entrypoint pattern followed
- Fallback behavior defined
- Flag name follows conventions
- Documentation updated
Deployment Strategyโ
- Deploy code with flag disabled by default
- Enable flag in staging for testing
- Gradual production rollout via configuration
- Monitor metrics during rollout
Flag Managementโ
Configurationโ
Manage flags through:
- Environment variables for backend services
- Configuration files for frontend builds
- Runtime configuration for dynamic updates
Monitoringโ
Track flag usage:
- Activation rates: Percentage of users seeing new feature
- Error rates: Compare flagged vs. unflagged implementations
- Performance metrics: Monitor impact of new features
Cleanup Processโ
Remove flags after features are stable:
- Monitor period: 2 weeks minimum after 100% rollout
- Remove flag logic: Replace with direct implementation
- Update tests: Remove flag-related test scenarios
- Documentation: Update feature documentation
Examplesโ
Simple Toggleโ
import { useFeatureFlag } from '@ttoss/react-feature-flags';
const Dashboard = () => {
const showNewMetrics = useFeatureFlag('enhanced-metrics');
return <div>{showNewMetrics ? <EnhancedMetrics /> : <BasicMetrics />}</div>;
};
Complex Featureโ
import { FeatureFlag } from '@ttoss/react-feature-flags';
const CheckoutPage = () => {
return (
<div>
<FeatureFlag
name="streamlined-checkout"
fallback={<LegacyCheckoutFlow />}
>
<NewCheckoutFlow />
</FeatureFlag>
</div>
);
};
Related Documentationโ
- Development Process - Integration with PR workflow
- Testing Guidelines - Testing flagged features
- @ttoss/react-feature-flags - React implementation