# Flows

A flow connects a source to a destination, with an optional filter, transformation, delay and ordering.

A flow routes events from one source to one destination. It is also where you decide what each destination receives: which events, in what shape, how soon and in what order.

```text
source ─▶ [ filter ] ─▶ [ transformation ] ─▶ [ delay ] ─▶ destination
```

A source can have many flows, one per destination. A single request to that source produces one event per active flow whose filter it passes. A source can deliver to a given destination through only one flow.

## Create a flow

Open **Flows → New flow**, or `POST /v1/flows` ([reference](/api-reference/create-a-flow/)):

```bash
curl -X POST https://api.getensue.com/v1/flows \
  -H "authorization: Bearer ens_<key>" -H "content-type: application/json" \
  -d '{
    "source_id": "src_…",
    "destination_id": "dst_…",
    "filter": { "match": "all", "conditions": [{ "path": "type", "op": "eq", "value": "invoice.paid" }] },
    "transform_id": "trf_…",
    "delay_seconds": 30
  }'
```

| Field | What it does |
|---|---|
| `filter` | Only requests that match create an event. See [Filters](/gateway/filters/). |
| `transform_id` | Reshapes the body before delivery. See [Transformations](/gateway/transformations/). |
| `delay_seconds` | Holds each event for 1 second to 7 days before its first delivery. |
| `ordering` | Delivers events for the same key one at a time, in order. See [Ordering](/gateway/ordering/). |
| `compaction` | Merges updates about the same thing that wait in an [inbox](/agents/inbox-and-leases/). |
| `region` | Sends deliveries from a chosen region, when your workspace has one available. |

## Order of steps

A flow always runs its steps in the same order, so results are predictable:

1. The source verifies the request.
2. The flow's **filter** decides whether an event is created.
3. The **transformation** reshapes the body.
4. The **delay**, if any, holds the event.
5. The destination **delivers** it under its [delivery policy](/gateway/delivery-policy/).

## Changing a flow

Edits to a flow, its filter or its transformation apply from the next attempt, including to events that are already queued. Events keep the destination they were created with: deleting a flow does not cancel events it already created.

Set `status` to `paused` to stop a flow from creating events. Requests that arrive meanwhile are still stored, and you can [replay](/gateway/replay-and-dead-letters/) them once the flow is active again.

> [!TIP]
> Use several flows on one source to give each service its own slice and shape of the same traffic: billing gets paid invoices, analytics gets everything, and an agent inbox gets only failures.