For Chaos Engineering and Continuous Delivery
- What are feature flags?
- Feature Flagging for CD
- Common ways of implementing Feature Flagging
- Enabling disabling
Photo by Isaac Li Shung Tan on Unsplash
What are feature flags?
The concept of feature flags is simple. You can toggle a feature on or off based on certain conditions. And ideally, this requires zero downtime.
For example, an experiment feature can be turned on for some users but disabled for others.
There are many levels to feature flagging:
- Disable feature for specific users
- Disable the feature completely
- Disable the feature in case of certain conditions
Feature flagging can also help in AB Testing.
Feature Flagging for CD
Feature flags also help in CD. Rather than feature branching, everyone can work on a single branch, but the features that aren’t ready yet can be disabled on prod. This decouples release and feature. Feature flagging is probabilistic because, in practice, it leads to stale branches.
In case of chaos engineering, a feature flag can help reduce blast radius and improve resiliency. Suppose a feature fails; that feature can be disabled at a run time until fixed.
Common ways of implementing Feature Flagging
The simplest implementation of the feature flag is DB based. A list of features is stored along with a flag to enable or disable it. Each time a decision comes, DB is called to fetch the flag’s status.
Environment variables can also be used. Configuration management systems like Spring Cloud Config can also be used to store flags.
The code has an IF else statement that enables or disables the feature.
An even better approach to IF else is dependency injection. If a class can be instantiated conditionally, then we solved the feature flagging problem cleanly.
Having a class per feature and inheriting a common interface is the best approach here. In the planning features section of this blog post, you’ll find more ideas on how to reach this.
There are also full-blown services that help with feature flagging, like LaunchDarkly and FlagShip
- Feature Toggles (aka Feature Flags)
- DevOps Concepts: Feature Flags: An introductory video that explains feature flagging and branching.
- Feature Flags with Spring
- Togglz: A java library for feature flagging. It comes with a UI.
- FF4j: A java library similar to Togglz
- Unleash: Probably the best open source feature flagging product.