---
title: "(Optional) Spike multiple endpoints | Grafana Labs"
description: "Extend your spike script to hit more than one route, use URL grouping and tags, and compare burst behavior across endpoints in Grafana Cloud k6."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# (Optional) Spike multiple endpoints

> Note
> 
> This milestone is **optional**. The core path continues with **Turn spike results into action** after the next optional step. To skip the optional milestones, open **Turn spike results into action** in the sidebar.

Real applications expose many routes; burst capacity is rarely identical across them. A read-heavy cacheable endpoint may handle a spike while a write path or dependency-heavy API degrades first. This milestone extends your spike profile to hit **two** QuickPizza routes in the same test so you can compare behavior under the same VU ramp.

To keep the per-route metrics readable, this script uses two k6 features:

- **Groups** (`group()`) wrap related requests under a label so you can see combined timing for a logical action, such as “home” or “pizza API”.
- **Tags** (`tags: { name: '...' }`) attach a label to individual requests so k6 breaks metrics out per route instead of per raw URL, which also keeps metric cardinality low.

To spike multiple endpoints, complete the following steps:

1. Save a copy of your `spike.js` file as `spike-multi.js` so you can compare with your single-endpoint run later.
2. Replace the default function with a version that requests both the home page and the pizza API, using `group` and `tags` so Grafana Cloud k6 can break metrics out per route without blowing up metric cardinality:
   
   JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```javascript
   import http from 'k6/http';
   import { check, sleep, group } from 'k6';
   
   export default function () {
     group('home', function () {
       const res = http.get('https://quickpizza.grafana.com/', {
         tags: { name: 'GET_home' },
       });
       check(res, {
         'home status 200': (r) => r.status === 200,
       });
     });
   
     group('pizza API', function () {
       const payload = JSON.stringify({
         mustBeVegetarian: false,
         excludedIngredients: [],
         excludedTools: [],
         maxCaloriesPerSlice: 500,
         minNumberOfToppings: 2,
         maxNumberOfToppings: 5,
       });
       const res = http.post(
         'https://quickpizza.grafana.com/api/pizza',
         payload,
         {
           headers: {
             'Content-Type': 'application/json',
             Authorization: 'Token abcdef0123456789',
           },
           tags: { name: 'POST_api_pizza' },
         }
       );
       check(res, {
         'pizza status 200': (r) => r.status === 200,
       });
     });
   
     sleep(1);
   }
   ```
   
   Keep the same `export const options` block (stages and thresholds) as in your original `spike.js`.
3. Run the test locally, then send results to Grafana Cloud k6 the same way as in the **Visualize the spike in Grafana Cloud k6** milestone:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   k6 cloud run --local-execution spike-multi.js
   ```
   
   As in the earlier milestones, drop `--local-execution` (`k6 cloud run spike-multi.js`) to generate the load on cloud load generators, which is the better choice for higher VU counts.
4. In the Grafana Cloud k6 result, compare response time and errors **per tag or group** during the spike phase. The `group` labels and `name` tags you set are what let Grafana Cloud k6 split the metrics per route so you can compare them side by side.
   
   Note which route showed higher latency, errors, or slower recovery. Prioritize that route when you tune pools, timeouts, or rate limits for production.

In the next optional milestone, you add authentication headers driven by environment variables. If you prefer to move on to **Turn spike results into action**, open that milestone in the sidebar.
