For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • Get started
    • Overview
    • Onboarding
    • Get started
    • Launch Insights
    • LaunchDarkly architecture
    • LaunchDarkly vocabulary
  • AgentControl
    • AgentControl
    • Manage AgentControl
  • Feature flags
    • Create flags
    • Target with flags
    • Flag templates
    • Manage flags
    • Code references
    • Contexts
    • Segments
  • Releases
    • Releasing features with LaunchDarkly
    • Release policies
    • Percentage rollouts
    • Progressive rollouts
    • Guarded rollouts
    • Feature monitoring
    • Release pipelines
    • Engineering insights
    • Release management tools
    • Applications and app versions
    • Change history
    • Restoring previous flag versions
  • Observability
    • Observability
    • Session replay
    • Error monitoring
    • Logs
    • Traces
    • Observability metrics
    • Product analytics events
    • LLM observability
    • Alerts
    • Dashboards
    • Service map
    • Vega for auto-remediation
    • Observability MCP server
    • Search specification
    • Observability settings
    • Observability integrations
  • Experimentation
    • Experimentation
    • Experiment metric types
    • Experiment configuration
      • Creating experiments
      • Allocating experiment audiences
      • Randomization units
      • Variation reassignment
      • Mutually exclusive experiments
    • Managing experiments
    • Analyzing experiments
    • Multi-armed bandits
    • Holdouts
  • Metrics and events
    • Metrics in LaunchDarkly
    • Creating metrics
    • Metric groups
    • Events
    • Autogenerated metrics
  • Warehouse native
    • Warehouse native metrics
    • Setting up external warehouses
    • Creating experiments using warehouse native metrics
  • Infrastructure
    • Connect apps and services to LaunchDarkly
    • LaunchDarkly in China and Pakistan
    • LaunchDarkly in the European Union (EU)
    • LaunchDarkly in federal environments
    • Public IP list
  • Your account
    • Projects
    • Views
    • Environments
    • Tags
    • Teams
    • Members
    • Roles
    • Account security
    • Feature previews
    • Billing and usage
    • Changelog
Sign inTry it free
LogoLogo
On this page
  • Overview
  • Randomization units in metrics and experiments
  • Randomization units and flag targeting rules
  • Mark context kinds available for experiments
  • Randomization units and multi-contexts
ExperimentationExperiment configuration

Randomization units

Was this page helpful?
Previous

Variation reassignment

Next
Built with

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 in 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:

The "Metric definition" section of a new metric with the randomization unit called out.

The "Metric definition" section of a new metric with the randomization unit called out.

Later, when you create an experiment, select the same randomization unit to make the metric available to the experiment:

The randomization unit field on the experiment creation screen.

The randomization unit field on the experiment creation screen.

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 and flag targeting rules

When you create an experiment, you will select a flag and a flag rule to run the experiment on. The context kind that the flag rule targets should match the randomization unit of your experiment. We recommend running the experiment on a rule that targets a subsection of your contexts rather than the default rule. This helps ensure consistent experiment results.

Mark context kinds available for experiments

New context kinds that you create in the LaunchDarkly user interface (UI) are available for experiments by default. You can mark a context kind as available or unavailable for experiments from the Contexts list.

Context kinds automatically created from SDKs are not available for experiments by default

New context kinds automatically created from your SDKs are not marked as available for experiments by default. To make them available for experiments, follow the procedure below.

To make a context kind as available or unavailable for experiments:

  1. In the left navigation, click Code. The CodeControl menu appears.
  2. Click Contexts.
  3. Click the gear icon on the right. The context kinds list appears.
  4. Click the three-dot overflow menu next to the context kind you want to edit.
  5. Select Edit. The “Edit context kind” dialog appears.
  6. Check or uncheck the Available for experiments and guarded rollouts checkbox.
  7. (Optional) Check the Set as the default for experiments checkbox if you want new experiments to default to this context kind as the randomization unit.
  8. Click Save.

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:

Two multi-contexts with the same org key
1{
2 "kind": "multi",
3 "user": {
4 "key": "user-key-anna", // Anna has a unique user key
5 "name": "Anna",
6 },
7 "organization": {
8 "key": "org-key-global-health", // The org key is the same in both multi-contexts
9 "name": "Global Health Services",
10 }
11}
12
13{
14 "kind": "multi",
15 "user": {
16 "key": "user-key-jesse", // Jesse has a unique user key
17 "name": "Jesse",
18 },
19 "organization": {
20 "key": "org-key-global-health", // The org key is the same in both multi-contexts
21 "name": "Global Health Services",
22 }
23}

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