Feature Flags
- All new features should be thought of as feature flag and if it can be feature flagged or not.
- A feature flag allows enabling/disabling the feature at runtime without code changes or redeploys or with code changes.
- Developers must design features so they can be stopped, hidden, or disabled instantly if needed.
- Flags should be centralized (e.g.,
src/lib/featureFlags.ts) and typed to avoid misuse. - Remove stale flags once the feature is stable and rolled out to all users.
- The most important thing is to prevent spaghetti code and create code that is organized and standalone for reusability.
Example
ts
// lib/featureFlags.ts
export const featureFlags = {
newDashboard: true,
betaCheckout: false,
} as const;
// usage in component
if (!featureFlags.newDashboard) return <OldDashboard />;
return <NewDashboard />;