Feature Flag: What is It?
Définition
A feature flag (or feature toggle) is a development technique that enables activating or deactivating application features in production without modifying or redeploying code, providing granular control over the progressive rollout of new features.What is a Feature Flag?
A feature flag (also called feature toggle, feature switch, or feature gate) is a mechanism that controls the activation of a feature in an application without modifying the code or performing a new deployment. Concretely, the feature's code is present in production but wrapped in a condition that checks the flag's state (enabled or disabled). By changing the flag's value, typically via a dashboard or remote configuration, the feature appears or disappears instantly for targeted users.
Feature flags were born from the need to decouple code deployment from feature availability. Traditionally, deploying code automatically meant making all changes available to users. Feature flags break this link by allowing "dark" code deployments that can be activated later, for specific users only, or quickly deactivated if problems arise. It is a fundamental tool of modern continuous delivery and trunk-based development.
Why Feature Flags Matter
Feature flags transform how teams deploy and test features in production. They reduce risk, accelerate delivery cycles, and enable controlled experimentation.
- Risk-free deployment: New features are deployed to production but remain invisible. If a bug occurs, the flag is deactivated in seconds, without a code rollback.
- Progressive rollout: A feature can be activated for 1% of users, then 10%, then 50%, then 100%, allowing problems to be detected before they affect everyone.
- A/B testing: Feature flags enable showing two versions of a feature to different user groups and measuring which performs better.
- Kill switch: In case of performance issues or critical bugs, the feature is deactivated instantly without an emergency deployment.
- Trunk-based development: Developers can merge their code to the main branch even if the feature is not complete, since it is protected by a flag. This reduces long-lived branches and merge conflicts.
- Personalisation: Feature flags enable activating specific features for certain clients, countries, or user segments without maintaining separate code branches.
How It Works
A feature flag comprises three elements: a definition (flag name and parameters), an evaluation point in the code (the if/else condition checking the flag state), and a management system (dashboard, API, or configuration file) that enables changing the flag state without touching code.
In code, usage is straightforward. The application checks the flag state before executing the feature logic. If the flag is enabled, the new code runs. If disabled, the previous behaviour is maintained. Advanced systems allow granular targeting: activation by user percentage, by segment (beta users, premium clients), by geolocation, or by user attribute.
At Kern-IT, we integrate feature flags into our Django projects using solutions scaled to the project size. For small projects, a simple Django model with a Redis cache suffices. For larger projects, we use platforms like LaunchDarkly or Unleash that offer a management dashboard, advanced targeting, and usage metrics. The key is maintaining cleanup discipline: every feature flag has an expiry date, and obsolete flags are regularly removed to prevent technical debt accumulation.
Concrete Example
Consider an e-commerce platform project for a Belgian client. The team develops a new machine learning-based recommendation engine. The risk is that the new engine performs worse than the old one in certain edge cases, which could impact sales.
The team deploys the new engine to production behind a feature flag. Week 1: the flag is activated for 5% of users. Metrics show a 12% higher click-through rate on recommendations. Week 2: activation for 25% of users. A bug is detected on electronics product categories: the flag is deactivated for that segment in 30 seconds. After the fix, rollout resumes. Week 4: 100% of users are on the new engine. The flag is kept as a kill switch for one month, then the old engine code and the flag are removed during a cleanup sprint.
Implementation
- Choose the technical solution: Homegrown solution (Django model + cache) for small projects, SaaS platform (LaunchDarkly, Unleash, Flagsmith) for projects with advanced targeting needs.
- Define conventions: Name flags consistently (e.g., feature_new_checkout_flow), document each flag and assign it an owner and expiry date.
- Integrate into code: Wrap the new feature's code in a condition that checks the flag state. Keep evaluation points as high as possible in the code to minimise complexity.
- Configure targeting: Define targeting rules (percentage, segments, attributes) based on the rollout strategy.
- Monitor metrics: Instrument code to measure the feature's impact (performance, conversion, errors) based on the flag state.
- Clean up regularly: Schedule cleanup sessions to remove obsolete flags. A flag unchanged for 3 months should be removed and the code stabilised.
Associated Technologies and Tools
- LaunchDarkly: Leading feature management platform with advanced targeting, metrics, and multiple integrations.
- Unleash: Open-source feature flags solution, self-hostable, with a management dashboard and SDKs for most languages.
- Flagsmith: Open-source feature flags and remote configuration platform, available as SaaS or self-hosted.
- Django Waffle: Python library for Django that adds feature flags, switches, and samples directly in the Django admin.
- Redis: In-memory database often used as a cache for feature flag states, guaranteeing ultra-fast response times.
- Datadog / Grafana: Monitoring tools for visualising the impact of feature flags on performance and business metrics.
Conclusion
Feature flags are a powerful tool that transforms how teams ship features to production. By decoupling deployment from activation, they reduce risk, enable experimentation, and provide granular control over the user experience. At Kern-IT, we integrate feature flags into our projects once the product maturity warrants it, while maintaining strict cleanup discipline to prevent obsolete flag accumulation. It is a technical investment that quickly pays for itself in deployment serenity and rapid iteration capability.
The greatest danger of feature flags is not technical, it is organisational: the accumulation of forgotten flags. Each flag adds a conditional path in the code and therefore complexity. Establish a strict rule: every flag must have an owner and an expiry date. Schedule a 'flag cleanup day' at the end of each quarter to remove resolved flags. Your codebase will thank you.