A feature flag is a technique for changing application behavior without redeploying code. OpenFeature compares a flag, in its simplest form, to an if/else statement that can be controlled at runtime. Pete Hodgson uses the names feature flag and feature toggle for the same techniques.
A flag can be used to hide unfinished functionality from end users while making it available for internal testing. OpenFeature also lists releasing functionality to a small group of users first, A/B testing, and reducing production functionality affected by an outage among its use cases. Access can also be restricted based on user attributes such as geography or IP address.
How is a flag decision made?
In Hodgson's account, a Toggle Point is where the application chooses between alternative code paths. The Toggle Router provides the decision about which path to use. The Router can be implemented in different forms, from a simple in-memory structure to a distributed system.
In a simple configuration, an On or Off state is stored for each feature. The Router passes this state to the Toggle Point. In a more dynamic decision, contextual information such as the user can be considered for each request. The same flag can direct requests from different users to different code paths.
In Hodgson's Experiment Toggle example, the Router can use an algorithm based on the user ID to place the user in a group. The configuration contains information such as the sizes of the experiment and control groups. The Router uses this information as input when determining the group.
OpenFeature states that information used for evaluation can be held in the Evaluation Context. Static information, such as the host or application ID, can be configured globally. Dynamic information, such as the client IP address in a web application, can be passed during evaluation and merged with the static values.
Dynamic routing and dynamic configuration are not the same thing. According to Hodgson, an Ops Toggle can be reconfigured from On to Off in response to an outage in the system. An Experiment Toggle, meanwhile, can choose a different path based on the user for each request; even so, the experiment's configuration can remain fixed. Changing the experiment's parameters at runtime can affect the validity of the results.
Flag types by purpose
Hodgson examines flag types in terms of their lifespans and how dynamic the decision needs to be. Who manages the decision can also vary. Flags in the same application can serve separate purposes for deployment, experimentation, operations or access.
Release Toggle
A Release Toggle allows unfinished or untested code paths to be carried into production as latent code. Hodgson notes that this code path may never be turned on. One example of this use is integrating work into the shared integration branch while development continues and keeping the branch deployable to production.
A Release Toggle can separate deploying code from making functionality available to users. In Hodgson's example, if a product feature works for only some delivery partners, it can be kept hidden from users until it has been implemented for all partners. Flags of this type are transitional; a flag related to making a product available can remain in place longer.
Experiment Toggle
An Experiment Toggle is used for A/B testing or multivariate testing. In Hodgson's account, users are divided into groups. The Toggle Router routes a user to the same code path at runtime according to the group they belong to. The effects of the code paths are compared by monitoring the aggregate behavior of the groups.
The experiment configuration remains the same for long enough to obtain statistically significant results. This period depends on traffic patterns. Hodgson also points to the risk that other changes to the system during the experiment may invalidate the results. The routing decision is dynamic because each request may be on behalf of a different user.
Ops Toggle
An Ops Toggle controls operational aspects of system behavior. Hodgson describes how this type of flag can be used for functionality whose performance impact is uncertain. Operators can quickly turn off the functionality in production or reduce its scope when necessary.
Some Ops Toggles are temporary. Others are kept in place for a long time to reduce noncritical functionality under heavy load. In Hodgson's example, a recommendation panel that is expensive to generate can be turned off under heavy load. These controls are used to respond quickly to production problems and require rapid reconfiguration.