100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
DevOps

Feature Toggle

BeginnerTechnique10.7K learners

A feature toggle (also called a feature flag) is a conditional switch in code that turns a feature on or off at runtime without requiring a new deployment.

Definition

A feature toggle (also called a feature flag) is a conditional switch in code that turns a feature on or off at runtime without requiring a new deployment.

Overview

Feature toggles decouple deploying code from releasing a feature to users. Instead of merging a branch and having that change go live to everyone the moment it ships, developers wrap the new code path in a conditional check against a flag, deploy it disabled, and turn it on later — instantly, and without another deployment — once it's ready, whether that means a specific moment, a specific set of users, or a gradual rollout percentage. Martin Fowler and Pete Hodgson's widely cited categorization splits toggles into several types with different lifespans and purposes: release toggles hide incomplete work behind a flag so trunk-based development can continue without long-lived feature branches; experiment toggles power A/B tests by routing different users to different code paths; ops toggles act as an operational kill switch to disable a risky feature under load or during an incident; and permission toggles gate functionality by user tier, such as enabling a feature only for beta or enterprise customers. Simple toggles can be a hardcoded boolean or an environment variable, but most production systems use a feature-flag management service (LaunchDarkly, Unleash, Flagsmith, or a provider's own flagging service) that supports targeting rules, percentage rollouts, and remote real-time updates without a redeploy. The main risk of feature toggles is accumulated complexity: every toggle left in the codebase after it has served its purpose adds a conditional branch and a combinatorial testing burden, so toggle hygiene — removing flags once a feature is fully rolled out or fully reverted — is considered as important as the toggling mechanism itself.

Key Concepts

  • Runtime on/off control over a code path without redeploying
  • Support for percentage-based or targeted rollouts to specific user segments
  • Distinct toggle categories: release, experiment, ops, and permission toggles
  • Enables trunk-based development by hiding unfinished work behind a disabled flag
  • Acts as an operational kill switch to quickly disable a problematic feature
  • Often backed by a dedicated feature-flag management service with an SDK and dashboard
  • Requires toggle-lifecycle hygiene to avoid accumulating stale conditional branches

Use Cases

Merging incomplete features to the main branch safely under trunk-based development
Running A/B tests and experiments by routing users to different code paths
Gradually rolling out a risky change to a small percentage of traffic before a full release
Providing an emergency kill switch to disable a feature during an incident
Gating premium or beta functionality by subscription tier or user group
Decoupling deployment schedules from marketing or business release timing

Frequently Asked Questions

From the Blog