This topic explains how to set up context kinds for use in guarded rollouts.
All LaunchDarkly accounts include a limited trial of guarded rollouts. Use them to understand how well the feature supports your release process in production.
A guarded rollout uses a single context kind, called a randomization unit, to determine how to assign traffic to flag variations.
Most guarded rollouts use the request or user context kind as the randomization unit. This means the rollout assigns the new or original variation based on the request or user encountering the flag. You can also use another context kind, such as device or organization, depending on how your application is configured.
The randomization unit must be available in both the flag and in any metrics you want to monitor.
We recommend choosing a randomization unit that represents a large number of unique contexts. This helps LaunchDarkly detect performance differences between variations more quickly.
A minimum number of contexts must be served the new variation before the next stage of the rollout begins. If this minimum requirement is not met, LaunchDarkly automatically extends the current stage to allow more contexts to receive the new variation. If the requirement is still not met after the extension period, LaunchDarkly rolls back the release.
For backend-only changes, the request context kind is often the best choice. Systems typically generate many distinct requests, and backend metrics like latency and error rate are usually measured per request.
To use request contexts, configure a context with the kind set to "request" and a key that uniquely identifies the request and remains consistent throughout the request lifecycle:
A user randomization unit is often the best choice for:
Most LaunchDarkly SDKs use user contexts by default. Ensure that your user keys uniquely identify individual users of your application. If they represent something else, such as organizations or requests, rollouts may not behave as expected.
To use user contexts, configure a context with the kind set to "user" and a key that uniquely identifies the user across all interactions:
If your application supports both logged-in and logged-out end users, make sure each user has a distinct key that remains consistent throughout their experience. To learn more, read Maintaining consistency across user sessions when running experiments.
To make a context kind available for use in your guarded rollouts, you must instrument your application code consistently. To simplify this, we recommend using multi-contexts to include multiple context kinds in each flag request.
For example, if your application has both a frontend and a backend service:
user and device.user and request. Use this multi-context when evaluating flags.
In LaunchDarkly, the default context kind of user is automatically available for use in guarded rollouts. If you have created other context kinds and want to use them as randomization units, make sure they are marked as Available for experiments and guarded rollouts. To learn more, read Mark context kinds available for experiments.

After that, you can configure any metrics that apply to that context kind to use it as a randomization unit.
When creating a guarded rollout, you must choose a randomization unit supported by all the metrics you want to monitor. Only context kinds supported by the selected metrics’ randomization units are available for guarded rollouts.