Search…
Traffic Splitter
Traffic Splitters can be used to expose multiple RealtimeAPIs as a single endpoint for A/B tests, multi-armed bandits, or canary deployments.

Configuration

1
- name: <string> # name of the traffic splitter (required)
2
kind: TrafficSplitter # must be "TrafficSplitter" for traffic splitters (required)
3
networking: # networking configuration (default: see below)
4
endpoint: <string> # the endpoint for the traffic splitter (default: <name>)
5
apis: # list of Realtime APIs to target (required)
6
- name: <string> # name of a Realtime API that is already running or is included in the same configuration file (required)
7
weight: <int> # percentage of traffic to route to the Realtime API (all non-shadow weights must sum to 100) (required)
8
shadow: <bool> # duplicate incoming traffic and send fire-and-forget to this api (only one shadow per traffic splitter) (default: false)
Copied!

Example

This example showcases Cortex's Python client, but these steps can also be performed by using the Cortex CLI.

Deploy a traffic splitter

1
traffic_splitter_spec = {
2
"name": "sentiment-analyzer",
3
"kind": "TrafficSplitter",
4
"apis": [
5
{"name": "sentiment-analyzer-a", "weight": 50},
6
{"name": "sentiment-analyzer-b", "weight": 50},
7
],
8
}
9
10
cx.deploy(traffic_splitter_spec)
Copied!

Update the weights

1
new_traffic_splitter_spec = {
2
"name": "sentiment-analyzer",
3
"kind": "TrafficSplitter",
4
"apis": [
5
{"name": "sentiment-analyzer-a", "weight": 1},
6
{"name": "sentiment-analyzer-b", "weight": 99},
7
],
8
}
9
10
cx.deploy(new_traffic_splitter_spec)
Copied!

Update the target APIs

1
new_traffic_splitter_spec = {
2
"name": "sentiment-analyzer",
3
"kind": "TrafficSplitter",
4
"apis": [
5
{"name": "sentiment-analyzer-b", "weight": 50},
6
{"name": "sentiment-analyzer-c", "weight": 50},
7
],
8
}
9
10
cx.deploy(new_traffic_splitter_spec)
Copied!
Last modified 3mo ago