Randomization units
Overview
This topic explains what randomization units are and how to use them in LaunchDarkly Experimentation. An experiment’s randomization unit is the context kind the experiment uses to assign traffic to each of its variations.
When you create an experiment, you will choose a randomization unit that determines both:
- which context kind the experiment will allocate traffic to different variations by, and
- which metrics you can use in the experiment.
Most experiments use the user
randomization unit. This means that the experiment will sort contexts that encounter the experiment into different variations by user. You can also choose a different context kind, like device
or organization
.
Randomization units for metrics and experiments
To use a particular metric within an experiment, the metric and the experiment must use the same context kind as their randomization unit.
You select a metric’s randomization unit when you create it:
Later, when you create an experiment, select the same randomization unit to make the metric available to the experiment:
Like experiments, many metrics use a context kind of user
as their randomization unit, but can also use other kinds depending on what the metric is measuring. To learn more, read Creating and managing metrics.
Randomization units other than “user”
In LaunchDarkly, the default context kind of user
is automatically available for use in Experimentation. If you plan to use a context kind other than user
in an experiment, expand the section below to read about the additional steps required.
Configure randomization units other than user
To use a context kind other than user
in an experiment, you must first select an industry-standard randomization unit, and then map that context kind to that randomization unit.
Industry-standard randomization units
There are six industry-standard randomization units that you can use in Experimentation:
- user
- user-time
- guest
- guest-time
- organization
- request
LaunchDarkly limits experiments to randomizing by these six industry-standard units because other units might result in invalid results. If you have a context kind that doesn’t logically map to one of these industry-standard units, it may not be appropriate to use as a randomization unit. For examples of common context kind mapping, read the table in Map randomization units to context kinds.
For example, if you tried to use “country” as a randomization unit, your experiment would serve the same variation to everyone in a particular country. If your experiment had end users in the United States, Mexico, and Canada, the experiment might serve variation A to all end users in the United States and Canada, and variation B to all end users in Mexico. This could result in significantly uneven numbers of end users in each variation, and each variation would not include a random sampling of end users. At the end of the experiment, there would be no way to tell if variation A or B performed better in any given country.
Instead, if you wanted to view results by country, you could filter your results by context attribute. To learn more, read Filtering experiment results.
Map randomization units to context kinds
If you create a context kind other than user
that you want to use in experiments, then you must first map the new context kind to one of the industry-standard randomization units. To do this, select Available for experiments when creating a new context kind or editing an existing context kind, and then select the appropriate industry-standard randomization unit. To learn more, read Creating and editing context kinds.
Here is an example of mapping a new context kind of “customer” to the randomization unit “user”:
Multiple context kinds can be mapped to the same industry-standard randomization unit.
Examples of common mappings
This table includes the industry-standard randomization units and example context kinds that might be associated with them:
Experiments must use valid randomization units
If you’re unsure of which randomization unit to map to your context kind, start a Support ticket for help.
Randomization units and multi-contexts
If you use multi-contexts, you have options as to which context kind you want to use as a randomization unit for an experiment. Expand the section below to view an example.
Randomization units and multi-contexts
Imagine the user
Anna and the user
Jesse both work for the organization
Global Health Services. If they are both in an experiment that randomizes by organization
, Anna and Jesse will always be sorted into the same variation in the experiment, because their contexts share the same organization
. However, if they are in an experiment that randomizes by user
, then they could end up in different variations.
Here is what their multi-contexts would look like, though each SDK sends context data to LaunchDarkly in a slightly different format:
There are two ways you could randomize the multi-contexts in an experiment:
- if you randomize by
user
, Anna could be assigned to one variation, and Jesse could be assigned to the other variation because they have different user keys - if you randomize by
organization
, Anna and Jesse will both always be assigned to the same variation because they share the same organization key