Skip to content

Commit d86c96a

Browse files
committed
Addition of a new feature toggling practice
1 parent 05fd86d commit d86c96a

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

practices/feature-toggling.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Feature Toggling
2+
3+
- [Feature Toggling](#feature-toggling)
4+
- [Context](#context)
5+
- [In summary](#in-summary)
6+
- [Background](#background)
7+
- [What is feature toggling?](#what-is-feature-toggling)
8+
- [Why use feature toggles?](#why-use-feature-toggles)
9+
- [Types of toggles](#types-of-toggles)
10+
- [Managing toggles](#managing-toggles)
11+
- [Toggling strategy](#toggling-strategy)
12+
- [Toggle lifecycle](#toggle-lifecycle)
13+
- [Best practice lifecycle](#best-practice-lifecycle)
14+
- [Testing toggled features](#testing-toggled-features)
15+
- [Designing for failure](#designing-for-failure)
16+
- [Further reading](#further-reading)
17+
18+
## Context
19+
20+
- These notes are part of our broader [engineering principles](../principles.md).
21+
- Feature toggling contributes to safer delivery, reduced deployment risk, and enhanced responsiveness to change.
22+
- It supports practices aligned with [DevOps](devops.md) and [continuous delivery](continuous-delivery.md).
23+
24+
## In summary
25+
26+
- Feature toggling enables functionality to be turned on or off without deploying new code.
27+
- It separates deployment from release, allowing code to be safely deployed without activating a feature.
28+
- Toggles should be explicitly managed with clear naming, documented intent, and timely removal.
29+
- Toggle abuse (too many, long-lived, or undocumented flags) leads to tech debt and complex logic.
30+
31+
## Background
32+
33+
Feature toggling, also known as feature flags, is a technique for modifying system behaviour without changing code by checking a condition (usually externalised) at runtime. It is often used to control feature rollouts, manage risk, and test changes in production.
34+
35+
This is particularly powerful in continuous delivery environments where small, frequent changes are the norm. It supports practices like canary releases, A/B testing, and operational kill switches.
36+
37+
For a detailed and widely referenced introduction to this practice, see Martin Fowler's article on [Feature Toggles](https://martinfowler.com/articles/feature-toggles.html).
38+
39+
While some areas are looking to adopt a more enterprise-grade offering with Flagsmith, it's important to recognise that more minimal feature toggle approaches may be appropriate for smaller or simpler systems. The [Thoughtworks Technology Radar](https://www.thoughtworks.com/radar) notes that many teams over-engineer feature flagging by immediately adopting complex platforms, when a simpler approach (e.g., environment variables or static config) would suffice. However, irrespective of how the toggle is implemented, the **governance, traceability, and lifecycle management processes should be consistent**.
40+
41+
## What is feature toggling?
42+
43+
Feature toggling works by introducing conditional logic into the application code. This logic evaluates a configuration value or remote toggle to determine whether to execute a new or existing code path.
44+
45+
Toggles can be defined statically (e.g., environment variable or config file) or dynamically (e.g., via an external feature flag service). Dynamic toggles can be changed without restarting or redeploying the application.
46+
47+
## Why use feature toggles?
48+
49+
- **Decouple deployment from release**: Code can be deployed behind a toggle and activated later.
50+
- **Safe rollouts**: Enable features for specific users or teams to validate functionality before full rollout.
51+
- **Operational control**: Temporarily disable a feature causing issues without rollback.
52+
- **Experimentation**: Run A/B tests to determine user impact.
53+
- **Environment-specific behaviour**: Activate features in dev or test environments only.
54+
55+
## Types of toggles
56+
57+
According to Martin Fowler, toggles typically fall into the following categories:
58+
59+
- **Release toggles**: Allow incomplete features to be merged and deployed.
60+
- **Experiment toggles**: Support A/B or multivariate testing.
61+
- **Ops toggles**: Provide operational control for performance or reliability.
62+
- **Permission toggles**: Enable features based on user roles or attributes.
63+
64+
## Managing toggles
65+
66+
Poorly managed toggles can lead to complexity, bugs, and technical debt. Best practices include:
67+
68+
- Give toggles meaningful, consistent names.
69+
- Store toggle state in a centralised and observable system.
70+
- Document the purpose and expected lifetime of each toggle.
71+
- Remove stale toggles once their purpose is fulfilled.
72+
- Avoid nesting toggles or creating toggle spaghetti.
73+
- Ensure toggles are discoverable, testable, and auditable.
74+
75+
## Toggling strategy
76+
77+
Choose a feature flagging approach appropriate for the scale and complexity of your system:
78+
79+
- **Simple applications**: Environment variables or configuration files.
80+
- **Moderate scale and beyond**: Look to make use of [Flagsmith](https://www.flagsmith.com/), which support targeting, analytics, and team workflows.
81+
82+
Feature toggles should be queryable from all components that need access to their values. Depending on your architecture, this may require synchronisation, caching, or SDK integration.
83+
84+
## Toggle lifecycle
85+
86+
Toggles are intended to be short-lived unless explicitly designed to be permanent (e.g. permission toggles).
87+
88+
### Best practice lifecycle
89+
90+
1. **Introduce** the toggle with a clear purpose and target outcome.
91+
2. **Implement** the feature behind the toggle.
92+
3. **Test** the feature in both on/off states.
93+
4. **Roll out** gradually (e.g., canary users, targeted groups).
94+
5. **Monitor** the impact of the feature.
95+
6. **Remove** the toggle once the feature is stable and fully deployed.
96+
97+
Document toggles in your architecture or delivery tooling to ensure visibility and traceability.
98+
99+
## Testing toggled features
100+
101+
Features behind toggles should be tested in both their enabled and disabled states. This ensures correctness regardless of the toggle value.
102+
103+
- Write tests that explicitly set the toggle on and off.
104+
- Use test frameworks that allow injecting or mocking toggle values.
105+
- Consider test coverage for the toggle transitions (e.g., changing at runtime).
106+
- Ensure integration and end-to-end tests include scenarios where toggles are disabled.
107+
108+
This is particularly important for toggles that persist for more than one release cycle.
109+
110+
## Designing for failure
111+
112+
Feature toggles should never become a point of failure. Design your system so that it behaves predictably even if the toggle service is unavailable or fails to return a value.
113+
114+
Best practices:
115+
116+
- Default values: Every toggle should have a known and safe default (either on or off) hardcoded in the consuming service.
117+
- Fail-safe logic: Ensure that remote flag checks have timeouts and fallback paths.
118+
- Graceful degradation: Systems should still function, possibly with reduced capability, if a toggle cannot be resolved.
119+
- Resilient integration: SDKs or services used for toggling should not block startup or core paths.
120+
121+
## Further reading
122+
123+
- [Feature Toggles by Martin Fowler](https://martinfowler.com/articles/feature-toggles.html)
124+
- [Feature Management Maturity Model](https://launchdarkly.com/blog/the-feature-management-maturity-model/)
125+
- [Unleash Strategies and Best Practices](https://docs.getunleash.io/advanced/toggle-strategy)
126+
- [Flagsmith Docs](https://docs.flagsmith.com/)
127+
- [Feature Flag Best Practices](https://launchdarkly.com/blog/feature-flag-best-practices/)
128+
- [Thoughtworks Tech Radar](https://www.thoughtworks.com/radar/techniques/minimum-feature-toggle-solution)

0 commit comments

Comments
 (0)