You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -41,7 +40,7 @@ This is particularly powerful in continuous delivery environments where small, f
41
40
42
41
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).
43
42
44
-
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**.
43
+
While some areas are looking to adopt a more enterprise-grade offering with a dedicated feature toggling tool, 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**.
45
44
46
45
## What is feature toggling?
47
46
@@ -51,9 +50,9 @@ Toggles can be defined statically (e.g., environment variable or config file) or
51
50
52
51
## Why use feature toggling?
53
52
54
-
-**Decouple deployment from release**: Code can be deployed behind a toggle and activated later.
53
+
-**Decouple deployment from release**: Deploy code behind a toggle and activate it later.
55
54
-**Enable safe rollouts**: Enable features for specific users or teams to validate functionality before full rollout.
56
-
-**Support operational control**: Temporarily disable a feature causing issues without rollback.
55
+
-**Support operational control**: Temporarily disable a feature which is causing issues, without needing to rollback.
57
56
-**Enable experimentation**: Run A/B tests to determine user impact.
58
57
-**Configure environment-specific behaviour**: Activate features in dev or test environments only.
59
58
@@ -66,23 +65,27 @@ According to Martin Fowler, toggles typically fall into the following categories
66
65
-**Ops toggles**: Provide operational control for performance or reliability.
67
66
-**Permission toggles**: Enable features based on user roles or attributes.
68
67
68
+
> [!NOTE]
69
+
> While permission toggles can target users by role or attribute during a rollout or experiment, they are not a replacement for robust, permanent role-based access control (RBAC). Use RBAC as a separate, first-class mechanism for managing user permissions.
70
+
69
71
## Managing toggles
70
72
71
73
Poorly managed toggles can lead to complexity, bugs, and technical debt. Best practices include:
72
74
73
75
- Give toggles meaningful, consistent names.
74
-
- Store toggle state in a centralised and observable system.
75
76
- Document the purpose and expected lifetime of each toggle.
76
-
-Remove stale toggles once their purpose is fulfilled.
77
-
-Avoid nesting toggles or creating toggle spaghetti.
77
+
-Store toggle state in an observable system.
78
+
-Guard the feature behind a single toggle check, and pass the resulting behaviour or strategy through your code to minimise duplication and simplify removal.
78
79
- Ensure toggles are discoverable, testable, and auditable.
80
+
- Avoid nesting toggles or creating toggle spaghetti.
81
+
- Remove stale toggles once their purpose is fulfilled.
79
82
80
83
## Toggling strategy
81
84
82
85
Choose a feature flagging approach appropriate for the scale and complexity of your system:
83
86
84
87
-**Simple applications**: Environment variables or configuration files.
85
-
-**Moderate scale and beyond**: Look to make use of e.g. [Flagsmith](https://www.flagsmith.com/), which supports targeting, analytics, and team workflows.
88
+
-**Moderate scale and beyond**: Look to make use of a dedicated feature toggling tool, which supports targeting, analytics, and team workflows.
86
89
87
90
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.
88
91
@@ -105,16 +108,21 @@ Document toggles in your architecture or delivery tooling to ensure visibility a
105
108
106
109
Features behind toggles should be tested in both their enabled and disabled states. This ensures correctness regardless of the toggle value.
107
110
108
-
- Write tests that explicitly set the toggle on and off.
109
-
- Use test frameworks that allow injecting or mocking toggle values.
110
-
- Consider test coverage for the toggle transitions (e.g., changing at runtime).
111
-
- Ensure integration and end-to-end tests include scenarios where toggles are disabled.
111
+
- Prefer testing the behaviour behind the toggle (e.g. via Strategy implementations) directly, rather than toggling features within tests.
112
+
- Where the Strategy Pattern is used, write separate unit tests for each strategy to validate their behaviour in isolation.
113
+
- If toggling is required in tests, use frameworks that allow injecting or mocking toggle values cleanly.
114
+
- Ensure integration and end-to-end tests include scenarios with the toggle both enabled and disabled, especially if the toggle is expected to persist across multiple releases.
115
+
- Include toggle state in test names or descriptions to clarify test intent (e.g. `shouldReturnNull_whenFeatureDisabled()`).
116
+
- Track test coverage across both toggle states and regularly review it for long-lived or critical toggles.
117
+
- Ensure test coverage includes edge cases introduced by toggled logic, such as different user roles, environment-specific behaviour, or state transitions.
118
+
- Use contract tests where toggled behaviour affects external APIs or integrations to ensure they remain backward-compatible.
119
+
- Avoid asserting on the presence or structure of toggle code itself, focus on testing expected outcomes.
112
120
113
121
This is particularly important for toggles that persist for more than one release cycle.
114
122
115
123
## Designing for failure
116
124
117
-
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.
125
+
If you are using a feature toggle service external to the application, 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.
118
126
119
127
Best practices:
120
128
@@ -123,12 +131,9 @@ Best practices:
123
131
- Graceful degradation: Systems should still function, possibly with reduced capability, if a toggle cannot be resolved.
124
132
- Resilient integration: Ensure that SDKs or services used for toggling are resilient and do not block application startup or core functionality.
125
133
126
-
## Comments
127
-
128
134
## Further reading
129
135
130
-
-[Feature Toggles by Martin Fowler](https://martinfowler.com/articles/feature-toggles.html)
131
-
-[Unleash Strategies and Best Practices](https://docs.getunleash.io/topics/feature-flags/feature-flag-best-practices)
132
-
-[Flagsmith Docs](https://docs.flagsmith.com/)
133
-
-[Feature Flag Best Practices](https://launchdarkly.com/blog/best-practices-for-coding-with-feature-flags/)
0 commit comments