Multi-contexts

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.

View multi-contexts

Multi-contexts appear individually in the Contexts list.

For example, your application may send a multi-context that contains the “user,” “organization,” and “device” context kinds, all in one evaluation call in the LaunchDarkly SDK. When this happens, all three individual contexts appear separately in your Contexts list. You can use the context kind filters to search for them separately.

If an individual context has an instance count higher than one, that means it is part of a multi-context. You can view the instance count for a context in the “Instances” column. Here, we know that the user context “Sandy Smith” is part of a multi-context because it has an instance count of 2:

A multi-context on the Contexts list.

A multi-context on the Contexts list.

To learn more, read The Contexts list.

Example multi-contexts: Anna at Global Health Services

Imagine Anna is a doctor who works for a hospital chain called Global Health Services. Anna works at two different locations, Springfield and Midway.

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 doctors working 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, each multi-context contains two associated contexts: one for user, and one for organization. Each Global Health Services location is its own organization context, with its own key. Anna’s user context is the same in both of her multi-contexts, so the organization key is what makes her Springfield visit and her Midway visit two separate context instances.

Here are Anna’s two multi-contexts, one for each location where she works. Each SDK sends context data to LaunchDarkly in a slightly different format, so your data structure may look different:

Anna's multi-contexts
1// Anna's multi-context at the Springfield location
2{
3 "kind": "multi",
4 "user": {
5 "key": "anna-user-key",
6 "name": "Anna",
7 "email": "anna@globalhealthexample.com",
8 "jobFunction": "doctor"
9 },
10 "organization": {
11 "key": "springfield-organization-key",
12 "name": "Global Health Services",
13 "address": {
14 "street": "123 Main Street",
15 "city": "Springfield"
16 }
17 }
18}
19
20// Anna's multi-context at the Midway location
21{
22 "kind": "multi",
23 "user": {
24 "key": "anna-user-key",
25 "name": "Anna",
26 "email": "anna@globalhealthexample.com",
27 "jobFunction": "doctor"
28 },
29 "organization": {
30 "key": "midway-organization-key",
31 "name": "Global Health Services",
32 "address": {
33 "street": "456 1st Ave",
34 "city": "Midway"
35 }
36 }
37}

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.