Dark Flag
A Dark Flag is a feature flag or toggle that, when disabled, triggers the deletion of code, configuration, or data associated with the feature it controls. Unlike regular feature flags which typically involve enabling or disabling code paths, dark flags are used for permanent removal and cleanup. The term "dark" implies that the removal process is generally invisible to the end-user, as the feature is intended to be completely retired.
Dark flags serve as a mechanism to ensure a smooth transition when removing a feature. Instead of directly deleting code, the dark flag provides a way to gradually phase out the feature, typically following these steps:
- Deprecation: The feature is marked as deprecated and is no longer actively developed or recommended for use.
- Deactivation: The dark flag is enabled, effectively disabling the feature. This might involve redirecting users, providing alternatives, or simply preventing access. Metrics and monitoring are crucial during this phase to ensure no unexpected consequences arise from the deactivation.
- Verification: After a period of monitoring and testing, and confirmation that the feature's removal hasn't caused any regressions or negative impact, the dark flag is switched to the 'off' state. This final step triggers the actual code and data deletion associated with the feature.
- Removal: The code and data associated with the deactivated feature is permanently removed, along with the dark flag itself.
The primary advantage of using dark flags is the ability to safely and controlled remove features with minimal risk of introducing bugs or data loss. It allows teams to confidently eliminate dead code, reduce technical debt, and streamline the codebase. They are particularly useful in large and complex systems where direct deletion might be risky due to unforeseen dependencies.
Common considerations when implementing dark flags include:
- Clear Ownership: Define who is responsible for managing the dark flag and overseeing the removal process.
- Monitoring and Metrics: Implement comprehensive monitoring to track the impact of disabling the feature.
- Communication: Inform users and stakeholders about the deprecation and removal timeline.
- Documentation: Document the purpose of the dark flag and the code/data it controls.
- Rollback Plan: Have a clear plan in place in case the deactivation causes unexpected issues and a rollback is required.
Dark flags are distinct from "kill switches," which are typically used for emergency shutdowns and system-wide failures. Dark flags are planned and deliberate for code cleanup, while kill switches are reactive measures for immediate problem mitigation.