# Batches and concurrency

A station doesn't run once per workpiece. Each run takes a **batch** from its `input/` and works through it, a few workpieces at a time.

| Setting | What it limits | Why |
|---|---|---|
| Batch size | How many workpieces one run takes | A run stays short, and its report stays readable. The rest wait in `input/` for the next run. |
| Concurrency | How many are worked on at the same moment | An outside service has a rate limit, and the machine has only so much memory and bandwidth |

**Every station has a batch size**, in its config or its code. No station takes all of `input/` in one run, however little is waiting today: a backlog arrives one day, and a run that tries to clear it is long, costly and hard to read. Even a station that needs only the newest workpiece takes a batch, oldest first, and the next run catches up.

Each workpiece in the batch succeeds or fails on its own. One that fails goes to `failed/` with its error, and the run carries on with the others: see [Bins](/docs/method/bins).

## Choosing the numbers

Start small and raise them when a run is slow and nothing is straining.

- **Calls to a language model or a paid API:** a few at once (3 is a common start). The provider's rate limit sets the ceiling.
- **Large downloads or uploads, or one shared connection:** one at a time.
- **Work on local files only:** more at once, if the disk keeps up.

## One at a time when workpieces share something outside

Workpieces run side by side only if each one touches nothing the others touch. When two in the same batch can act on the same outside thing, run them one after another:

- two attachments of one email, where each would move that email to another folder;
- two postings of the same job, where each would create a task for it;
- a ledger or account that accepts one write at a time anyway.

In order, the second one finds the first one's work already done and does nothing. Side by side, both can act at once.

## Related

- [Write a station that processes workpieces](/docs/guides/process-workpieces#run-several-at-once): setting the batch size and concurrency with lib-factory
- [Start stations](/docs/guides/trigger-stations): what starts the next run when work is left in `input/`
