> For the complete documentation index, see [llms.txt](https://docs.zerve.ai/zerve-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zerve.ai/zerve-docs/compute/fleet.md). Agents can also search and read this documentation through its [MCP server](https://docs.zerve.ai/zerve-docs/~gitbook/mcp).

# Fleet: parallel runs

Run the same block many times in parallel with Fleet.

**Fleet** runs the same blocks many times in parallel, once for each item in a list. Use it to process each ticker, each date or each parameter set at the same time, instead of one after another. You don't set up clusters or write any special parallel code.

## How it works

1. A block calls `spread()` with a list. This block starts the Fleet.
2. The blocks after it run once for each item in the list, in parallel, each on its own compute. In each run, the variable you assigned `spread()` to holds that run's item.
3. An [Aggregator](https://docs.zerve.ai/zerve-docs/notebooks/blocks/aggregator.md) block calls `gather()` to collect the results of every run into a list, in the same order as the items. This ends the Fleet.

`spread()` and `gather()` are built in, so you don't import them. `zrv_parallelize()` is another name for `spread()`.

## Example

This runs a backtest for each ticker in parallel, then combines the results.

```python
# Block 1: start the Fleet, one run per ticker
tickers = ["AAPL", "MSFT", "NVDA", "AMZN", "GOOGL"]
ticker = spread(tickers)
```

```python
# Block 2: runs once for each ticker, in parallel. Here, ticker is one ticker.
result = run_backtest(ticker)
```

```python
# Aggregator block: collect every run's result into one list
results = gather(result)
```

`results` is a list of five results, in the same order as `tickers`.

## Writing Fleet blocks

* **Keep items small.** Each item is saved as JSON, so it must be something JSON can hold: a string, a number, a list, or a dict of parameters or IDs. Pass a ticker or a date, not a dataframe, and load the data inside the run.
* **Write each block for a single item.** The blocks between `spread()` and the Aggregator see one item at a time. You can chain several of them; each run carries on from its own results.
* **Use earlier results freely.** Blocks before the Fleet starts, such as one that loads reference data, are shared by every run.
* **Name scratch variables with `_`.** Variables starting with `_` aren't saved, so they don't clutter the results. See [Variables, outputs and caching](https://docs.zerve.ai/zerve-docs/notebooks/variables-outputs-and-caching.md).
* **Start one Fleet at a time.** A run can't have more than one `spread()` before it.

## What the Aggregator gets

Each variable the runs **create or change** becomes a collection, with one item per run, in order. Variables the runs only **read** pass through unchanged.

| To                              | Use                                      |
| ------------------------------- | ---------------------------------------- |
| Get every run's value as a list | `gather(x)` or `x.collect()`             |
| Count the runs                  | `len(x)`                                 |
| Get one run's value             | `x[0]`, `x[-1]`, or a slice like `x[:3]` |
| Go through them                 | `for value in x:`                        |

## Testing a Fleet

Before running every item, select **Test run** in the block's toolbar to run it once, with the first item. It's a quick way to check the code works before starting the whole Fleet.

## Following a Fleet

In [Canvas View](https://docs.zerve.ai/zerve-docs/notebooks/notebook-and-canvas.md), Fleet blocks are labeled with where the Fleet starts and ends, and how many runs it has.

The Fleet view shows every run with its status and how long it took:

| Status        | Meaning                                                                                     |
| ------------- | ------------------------------------------------------------------------------------------- |
| **Pending**   | Not started yet                                                                             |
| **Queued**    | Waiting for a free slot, because the Fleet or your organization is at its concurrency limit |
| **Running**   | Running now                                                                                 |
| **Completed** | Finished successfully                                                                       |
| **Failed**    | Finished with an error                                                                      |
| **Skipped**   | Didn't run                                                                                  |

You can see the runs as a table, filter them by item number or by how long they took, and follow a run's output live. A chart of run times shows the shortest, median, 95th percentile and longest, and picks out unusually slow runs.

## When runs fail

If any run fails, the block shows as failed, with the message "One or more concurrent jobs have failed!" and the first error. Runs that succeeded keep their results.

| If runs failed because of                                    | Do this                                                |
| ------------------------------------------------------------ | ------------------------------------------------------ |
| **A temporary problem**, such as a timeout or a lost machine | **Retry failed runs**. Only the failed runs run again. |
| **A bug in your code**                                       | Fix the code and run the Fleet again                   |

You can also stop a Fleet as a whole, which stops all its runs.

## Limits

| Limit                    | Value                                                                                                                                                                                                                                                                           |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Runs in one Fleet**    | Up to 250                                                                                                                                                                                                                                                                       |
| **How many run at once** | You can set a limit on the block that starts the Fleet, within your organization's overall [concurrency limit](https://docs.zerve.ai/zerve-docs/compute/limits-and-concurrency.md). Set one when runs call a rate-limited API or database. Runs over the limit wait in a queue. |

## Common uses

| Use                                  | Example                                                                                            |
| ------------------------------------ | -------------------------------------------------------------------------------------------------- |
| **Processing by entity**             | Running the same analysis for each stock, fund or region                                           |
| **Hyperparameter tuning**            | Training a model with many parameter combinations at once, then picking the best in the Aggregator |
| **Processing by category or period** | Processing each category, or each month, of a large dataset separately                             |
| **Model evaluation**                 | Testing a model or prompt against many inputs at once                                              |

Fleet isn't a good fit for small loops, or for work where each step depends on the one before.

## Fleet and superagents

Superagents have their own way of running work in parallel, called [batches](https://docs.zerve.ai/zerve-docs/superagents/batches.md), which run whole agents rather than blocks of code.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zerve.ai/zerve-docs/compute/fleet.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
