No results for ""
EXPAND ALL
  • Home
  • API docs

Multi-contexts

Read time: 2 minutes
Last edited: Nov 25, 2024

Overview

This topic includes information about multi-contexts. Contexts are people, services, machines, or other resources that encounter feature flags in your product. Multi-contexts are combinations of several context kinds into one context. Multi-contexts allow your feature flags to target entities based on data from multiple contexts. For multi-contexts, the context kind is set to multi.

This is a representation of what two multi-contexts might look like:

Two multi-contexts with three contexts each of "user," "organization," and "location."
Two multi-contexts with three contexts each of "user," "organization," and "location."

Example multi-context: Anna at Global Health Services

For example, imagine Anna is a doctor who works for a hospital chain called Global Health Services. Anna works at two different locations, Springfield and Midway. Jesse is a nurse that works with Anna at the Springfield location.

Maybe you want to serve one variation of a flag to doctors working at the Global Health Services Springfield location, and a different variation to nurses at the Springfield location, and you want to serve a third variation to doctors at the Midway location. In this situation, you can have the LaunchDarkly SDK send multiple contexts at once during the flag evaluation, so that LaunchDarkly can evaluate targeting rules using data from both the "user" and "organization" contexts at the same time.

In this example, the multi-contexts contain two associated contexts: one for user, and one for organization.

Here is an example of what the data structure might look like for these two multi-contexts, though each SDK sends context data to LaunchDarkly in a slightly different format:

This configuration allows you to target the user and organization together to ensure you serve the correct variation. This helps eliminate risk and ensure accuracy in complex deliveries.

The multiple contexts that appear in a multi-context are called "associated contexts." For example, the Anna user context and the Global Health Services organization context are associated contexts.