---
title: "Multi-Service Replay | Speedscale Docs"
description: "Configure Speedscale for Multi-Service Replay to simulate API interactions, merging snapshots for authentication and API traffic testing."
canonical: "https://docs.speedscale.com/guides/replay/multi-service-replay/"
---

[Documentation index](https://docs.speedscale.com/guides/llms.txt) | [Markdown](https://docs.speedscale.com/guides/replay/multi-service-replay/index.md) | [Canonical page](https://docs.speedscale.com/guides/replay/multi-service-replay/)

# Multi-Service Replay

Some applications require communication between multiple services to work correctly. For example, imagine an API server which requires an authentication token. In production a client might make a request to an auth service to get a token, then send that token to the API server. In this guide we will configure Speedscale to run a [replay](https://docs.speedscale.com/reference/glossary/#replay) simulating this example.

<a id="replay-two-services-from-one-snapshot"></a>

## Replay two services from one snapshot

Append a snapshot and map each recorded service to its test workload.

[Download the video](https://docs.speedscale.com/videos/guides/speedscale-replay-two-services-from-one-snapshot.mp4)

<a id="create-snapshot"></a>

## Create Snapshot

<a id="select-traffic"></a>

### Select Traffic

To start we will need to create two [snapshots](https://docs.speedscale.com/reference/glossary/#snapshot) and merge them together.

The first snapshot contains only the authentication request and response. In this banking example, the `banking-user` service provides the token we need from `POST /api/users/login`.

![The Traffic viewer filtered to banking-user and the /api/users/login endpoint, listing only login requests](https://docs.speedscale.com/assets/images/traffic-auth-login-ce5677f62e1b8938022b599a24d74348.png)

The second snapshot contains traffic to the API server we want to test, `banking-accounts` in this case.

![The Traffic viewer filtered to banking-accounts, with its inbound requests and its calls to Postgres and external APIs](https://docs.speedscale.com/assets/images/traffic-api-requests-c6203a5496a1a8ea6ee8a31ae78faddb.png)

<a id="merge-snapshots"></a>

### Merge Snapshots

From the first snapshot containing the authentication request, open the menu at the top right and choose **Append snapshot**.

![The snapshot actions menu, with Append snapshot under Edit snapshot](https://docs.speedscale.com/assets/images/append-snapshot-d93d1dbf1fc2fbaab4a8662d3ad55547.png)

Then select the second snapshot and select **Append**. By default **Create a new merged snapshot instead of modifying this snapshot** is checked, so the merge is saved as a new snapshot and the first one does not change.

![The Select snapshot to append dialog, with a banking-accounts snapshot selected and Create a new merged snapshot checked](https://docs.speedscale.com/assets/images/select-append-snapshot-b446c45a776d46a46c125a3093ed8e16.png)

Now the merged snapshot contains traffic from both services.

Just to be sure we can investigate the snapshot traffic to verify by pulling the snapshot files and looking at the `resource` fields in the [action file](https://docs.speedscale.com/reference/glossary/#action-file):

```shell
$ speedctl pull snapshot $SNAPSHOT_ID
$ cat ~/.speedscale/data/snapshots/$SNAPSHOT_ID/raw.jsonl | head -n 5 | jq '.resource'
"banking-user"
"banking-accounts"
"banking-accounts"
"banking-accounts"
"banking-accounts"
```

The first request is from `banking-user` and the rest are from `banking-accounts`. The **Overview** tab of the new snapshot shows the inbound and outbound [traffic](https://docs.speedscale.com/reference/glossary/#traffic) from both services.

<a id="transforms"></a>

### Transforms

The snapshot now contains the `/api/users/login` request, which means that request will be made again during the replay to retrieve a new token, but this is not enough. We need to configure Speedscale to pass the `token` from the login response to the `Authorization` header in subsequent requests.

We will create [Transforms](https://docs.speedscale.com/reference/glossary/#transform) to [store](https://docs.speedscale.com/guides/transformation/transforms/variable_store/) the `token` from the login response body and [load](https://docs.speedscale.com/guides/transformation/transforms/variable_load/) it into the header field later. Transforms for the snapshot are created on its **Prepare** tab.

Store the token by selecting the `/api/users/login` [RRPair](https://docs.speedscale.com/reference/glossary/#rrpair) on the **Traffic** tab, opening **Response**, clicking the pencil by the `token` field and choosing **Modify token**.

![The pencil menu on the token field of a login response, with Modify token](https://docs.speedscale.com/assets/images/transform-login-pencil-d15a11ef6f2973a9697517b6a5aaf1da.png)

On the **Prepare** tab, select **Add step**, pick `Store Variable` and enter a variable name.

![A transform chain on the login response with a JSON Path step and a Store Variable step](https://docs.speedscale.com/assets/images/transform-store-var-61afcab263b42d960d01d093ce6b4e3d.png)

Now we can manually create a new transform by clicking **New** at the top of the Prepare list. The new transforms will:

*   Match all requests EXCEPT those with endpoint `/api/users/login`
*   Target the HTTP Request Header `Authorization`
*   Load the stored variable into the header field at index 1, since the full header string is `Bearer [token]`

Now during replay the `Authorization` header for all requests, except the login itself, will contain the `token` from the response of the `/api/users/login` request which gives us the flexibility to test with our real service with real, valid authentication.

<a id="replay"></a>

## Replay

The merged snapshot now has traffic from both services and transforms to route to different locations. Let's replay it by clicking the **Replay** button.

<a id="cluster--namespace"></a>

### Cluster / Namespace

The replay page shows the service dependency map with both services, then numbered steps. In step 1, select the cluster and namespace where the replay will run. Make sure both target workloads are running there.

![Step 1 of the replay page, with both services in the dependency map and the dev-decoy cluster and banking-app namespace selected](https://docs.speedscale.com/assets/images/replay-wizard-select-cluster-ea1da2959fe6b108c6d70583bb68744a.png)

<a id="test-config"></a>

### Test Config

In step 2, select the type of test. The [test config](https://docs.speedscale.com/reference/glossary/#test-config) behind it sets details like load and duration. Pick a regression test, or select **Custom Scenario** to choose a saved config. Test configs are edited under **Test Configs** in the navigation.

![Step 2 of the replay page, with API Contract and Correctness expanded and Regression with service mocks selected](https://docs.speedscale.com/assets/images/replay-wizard-test-config-23977a164633b12c0d793eb91dda2317.png)

<a id="tests"></a>

### Tests

Step 3, **Choose where to send traffic**, has one row for each recorded service. Each row's target can be set separately.

![Step 3 of the replay page, with inbound rows for banking-accounts and banking-user and the target of each](https://docs.speedscale.com/assets/images/replay-wizard-two-services-be5001ab814b6c0d402539e2e0a05876.png)

Select the pencil on the `banking-accounts` row and pick where its recorded traffic should go. Here we select the `banking-accounts` Kubernetes service.

![The target editor for traffic recorded from banking-accounts, with Kubernetes Services selected and the banking-accounts service chosen](https://docs.speedscale.com/assets/images/replay-wizard-target-accounts-21351fb203f87934737670c1bac6a497.png)

Do the same for `banking-user` and select the `banking-user` service.

![The target editor for traffic recorded from banking-user, filtered to banking-user, with the banking-user service chosen](https://docs.speedscale.com/assets/images/replay-wizard-target-user-afcf9175bb4a551c64444661114040af.png)

Step 4 lists the dependencies each service called. Each one is mocked unless you exclude it.

<a id="start"></a>

### Start

Review the targets and mocks, then select **Start Replay**. **Run In Terminal** shows the same replay as a `speedctl infra replay` command, with one `--route` for each service.

![The Start Replay button and the Run In Terminal command, with a route for banking-accounts and one for banking-user](https://docs.speedscale.com/assets/images/replay-wizard-summary-4ec82de74b344d319876a89fd3f0e14e.png)
