Feature Flags
Control feature visibility at runtime without code deployments using conditional toggles evaluated per request or user.
Description
Feature flags are conditional statements that control whether a feature is visible or active for a given user, request, or environment. They decouple deployment from release, allowing code to be shipped to production in an inactive state and enabled incrementally. This enables practices like trunk-based development (where all developers commit to main), gradual rollouts, A/B testing, kill switches for problematic features, and subscription-tier gating.
Feature flags can be simple boolean toggles stored in environment variables, or sophisticated systems with user targeting (by ID, email domain, geography, percentage rollout), flag dependencies, and audit trails. Dedicated feature flag platforms (LaunchDarkly, Flagsmith, Unleash, PostHog) provide SDKs with local caching, streaming updates, and fallback behavior when the flag service is unreachable. Server-side evaluation ensures security, while client-side evaluation reduces latency for UI flags.
Managing feature flag lifecycle is critical to avoid technical debt. Flags should be categorized by type: release flags (short-lived, remove after full rollout), ops flags (semi-permanent, for operational control like circuit breakers), experiment flags (time-bounded, for A/B tests), and permission flags (long-lived, for entitlements). Stale release flags that are fully rolled out should be cleaned up promptly. Code should always handle both flag states gracefully, and the default fallback value should be the safe option (typically the feature being disabled).
Prompt Snippet
Integrate a feature flag system using LaunchDarkly SDK (or self-hosted Unleash) with server-side evaluation. Initialize the client at application startup with a 5-second connection timeout and define a sensible default (feature-off) for all flags. Use typed flag variations (boolean, string, JSON) with context objects including user ID, plan tier, and geographic region for targeting rules. Implement a React provider component that streams flag updates via SSE for client-side flags. Wrap all flag-gated code paths with logging to track flag evaluation decisions. Establish a quarterly flag cleanup process and lint rule that flags TODOs referencing feature flag identifiers older than 90 days.
Tags
Related Terms
Canary Releases
Gradually roll out changes to a small subset of users before full deployment to detect issues with minimal blast radius.
Environment Variable Management
Externalize application configuration into environment variables to separate config from code across environments.
Zero-Downtime Deployments
Deploy application updates without any period of unavailability by gradually replacing old instances with new ones.