Creating flag variations
Read time: 3 minutes
Last edited: Jun 15, 2022
This topic explains how to use a flag's Variations tab to create and edit your feature flag's variations and outlines the different types of flag variations.
Flag variations are available across all environments in a project. Flag targeting is environment-specific. For example, if you add a new flag variation, it is immediately available in all environments in your project. If you change the default targeting rule to serve a different variation, the targeting change only applies to the current environment. To learn more, read Configuring the same flag in different environments.
LaunchDarkly supports boolean and multivariate flags. On the Variations tab, you can add, edit, or delete variations of existing flags:
- Boolean flags have two variations:
- Multivariate flags can have more than two variations. The allowed variations depend on the type of flag. Multivariate flag types are strings, numbers, and JSON. To learn more, read Understanding multivariate flags.
After a feature flag has been created, you cannot change the type of its variations. For example, you can't edit a feature flag that returns numbers to make it return strings instead. To learn more about creating flags, read Creating a feature flag.
Here is an image of a multivariate flag:
When you add, edit, or delete a feature flag's variations, the change impacts environments within the project.
When you delete a variation, custom rules that return that variation are also deleted. If a custom rule has a percentage rollout, the rollout for that variation is set to zero. If the default rule returns the deleted variation, it will change to return the default off value instead.
LaunchDarkly allows you to delete variations that are designated to be served when targeting is off. Make sure that your application is able to handle a null value when targeting is off in case this happens.
When you create a feature flag, some of its values are designated as defaults. A flag's default values are the values that are served when a flag is on or off, unless you specify otherwise. The default value when a flag is On can be either a single variation or a rollout. The default value when a flag is Off can be only a single variation.
For example, a boolean flag could have
true set as its default rule when on and
false set as its default off variation. A multivariate flag could have
variation 2 set as its default rule when on and
variation 1 set as its default off variation, with
variation 3 and
variation 4 configured to appear when users match certain targeting rules.
Default values are designated automatically every time you create a feature flag. You can accept the default values or change them. When you change the default values and save a flag, you create the flag across all environments in your project with these values set as its defaults.
Here is an image of a flag's default values:
You can change a flag's default values from the Variations tab. Update the default variations in the "Default variations for new environments" section. Subsequent environments you create also use the flag's default values. If you change the default values and then create a new environment, the environment you create will use the latest default values.
If you modify a flag's default values, the updated defaults only apply to new environments. You can not change the default values in environments that already exist.
Multivariate flags let you use one flag to serve more than two variations of a feature simultaneously. There is no limit to the number of variations you can add to a multivariate flag, making it useful for complex use cases and for managing multiple variations of a feature.
Multivariate flag variation types include strings, numbers, or JSON. To learn more, read Understanding flag types.
You can use a percentage rollout to refine the rollout of a feature. For example, a multivariate flag that serves strings as variations can be used to enable different customer checkout types, serving a percentage rollout of those types to users. In this example, the default rule serves one-click checkout to 10% of users, two-click checkout to 10% of users, and the original checkout flow to 80% of users.
Here is an image of a flag with a percentage rollout:
You can use custom rules to target multiple sets of users and refine a rollout even more. In this next example, the first rule serves two-click checkout to all users whose country is
US. The second rule targets users whose email ends with
.edu and serves one-click checkout to 10%, two-click checkout to 10%, and the original checkout flow to 80% of those users. All users who are not targeted in the custom rules are served the default rule.
Here is an image of a flag with custom rules:
To learn more about targeting rules, read Creating targeting rules.
You can also use multivariate flags to perform testing with LaunchDarkly's Experimentation feature. To learn more, read Creating Experiments.