Feature flags instead of code branches
Without flags, every deploy waits on a coordinated release.
react-platform-feature-flags-not-branches
Why it matters
| Stake | If ignored |
|---|---|
| Hard to change |
|
| Unsafe to delete |
|
How to fix
A new capability ships behind a flag. The flag is controlled from outside (configuration, not code). When the capability is mature — delete the flag, do not leave it "just in case".
Examples
ts
function generateResponse(prompt: string) {
if (process.env.NEW_PROMPT_FORMAT === 'true') return newFormat(prompt);
if (window.location.hostname.includes('staging')) return experimentalFormat(prompt);
return legacyFormat(prompt);
}ts
// libs/shared/feature-flags/src/lib/flags.ts
export const flags = {
newPromptFormat: isEnabled('new-prompt-format'),
};
// usage
import { flags } from '@acme/shared/feature-flags';
function generateResponse(prompt: string) {
return flags.newPromptFormat ? newFormat(prompt) : legacyFormat(prompt);
}