Skip to content
Reference

Large batches

Read a query result or a CSV file of a million rows or more as one message per row, a chunk at a time, with a flat backlog, a checkpoint and pause, resume and cancel.

On this page

A batch reads a large result, a BigQuery query, a SQL SELECT, a CSV file on an SFTP server or a paginated REST API, and runs the workflow once for each row. It reads a chunk of rows at a time and reads the next chunk only when the workflow has room, so a million-row backfill never floods the engine and other traffic keeps flowing.

How it works

  1. The engine reads one chunk (1,000 rows by default, at most 10,000).
  2. It writes every row of the chunk as a pending execution of the workflow, and the batch's checkpoint (where the next chunk starts), in one database transaction.
  3. The work runner runs those executions, like any other queued message.
  4. The engine reads the next chunk only when the workflow's backlog of pending executions is at or below the low-water mark: the max backlog minus one chunk. Writing a chunk therefore never takes the backlog past the max backlog.

The max backlog defaults to five chunks, at most half of WORKFLOW_MAX_PENDING (5,000 unless you change it), and can be at most WORKFLOW_MAX_PENDING minus one chunk, so other traffic to the workflow always has room while a batch runs. A workflow runs one batch at a time: starting a second while one is running or paused answers 409. The backlog cap applies to every way work reaches a workflow: inbound messages (MLLP, webhook, X12, FHIR subscriptions), polling triggers, Run workflow steps and batches. A full workflow refuses or postpones new work: an MLLP sender gets an AE, a webhook a 503, a poll waits for its next interval, a Run workflow step fails and its retry tries again.

Each row reaches the workflow as its message:

json
{
  "triggerType": "batch",
  "batchId": "7aaba6fd-97f6-4885-9939-51fd5e3d8943",
  "rowIndex": 41,
  "row": { "id": 41, "family": "TESTPATIENT" }
}

Sources

SourceQueryCheckpoint
Google BigQueryThe query step's settings: sql, with :name or @name parameters in params.The query job and its page token. One job serves the whole batch.
SQL databaseA SELECT that binds :after and :limit and orders by a unique key column.The last key read. The next chunk is the rows after it.
SFTPA CSV file: remotePath, with the CSV parse options in csv.The byte offset of the next unread row, and the file's size and modified time.
REST APIA Generic REST GET: endpoint or urlTemplate, optional query, and pagination.The next page's position, and how many of its items are already queued.

A SQL batch also sets keyColumn (the unique column the SELECT orders by) and keyInitial (a value below every key, such as 0):

sql
SELECT id, mrn, admitted_at
FROM encounters
WHERE id > :after
ORDER BY id
LIMIT :limit

CSV files over SFTP

A CSV parse step and the SFTP trigger's rows mode read a whole file into memory and stop at their maxRows (at most 100,000 rows for a parse, and at most WORKFLOW_MAX_PENDING for rows mode). Read a larger file as a batch. The engine streams the file: each chunk opens the file at the checkpoint and reads only that chunk's rows, so memory holds one chunk, never the file.

json
{
  "remotePath": "/outbound/encounters-2026.csv",
  "csv": { "delimiter": ",", "header": true },
  "encoding": "utf8"
}
  • The first row names the columns. It is read once and kept in the checkpoint. For a file without a header row, set csv.header to false: the columns are named col1, col2, … or by csv.columns.
  • The other CSV parse options work as in the transform: quote, escape, skipLines, trim, skipEmpty, strictColumns, recordDelimiter, and the column types in columns. maxRows does not apply: the chunk size bounds each read. The quote must be a one-byte (ASCII) character.
  • A quoted value may hold the delimiter, line breaks and escaped quotes. The checkpoint always points at the start of a row, so a row with a line break in a quoted value is never split between chunks.
  • encoding is utf8 (the default; a leading byte order mark is dropped) or latin1.
  • The file must not change while the batch runs. The checkpoint keeps the file's size and modified time from the first chunk. If either differs when the next chunk is read, the batch fails with FILE_CHANGED: The file changed since the batch started, rather than mixing rows from two versions of the file. Start a new batch for the new file. Write the file under a temporary name and rename it when it is complete, so a batch never starts on a half-written file.
  • A missing file (NOT_FOUND) or a file the login cannot read (PERMISSION_DENIED) fails the batch. A dropped connection or a timeout is retried from the checkpoint.
  • A value that does not parse fails the batch with its row number in the whole file, never the value.

Paginated REST APIs

A Generic REST profile reads an API page by page, with the profile's auth (OAuth2 included), the SSRF check on every page and the correlation header, as a paginated read step does. Each item of a page is one row; an item that is not an object becomes { "value": item }.

json
{
  "endpoint": "/appointments",
  "query": { "status": "booked" },
  "pagination": {
    "mode": "next-token",
    "itemsPath": "$.data",
    "nextPath": "$.meta.next"
  }
}
  • pagination is required and takes every mode of the read step: next-url, next-token, cursor, link-header, offset and page, with their itemsPath, nextPath, param, offsetParam, limitParam, limit, startPage, pageSize, pageSizeParam and retries. maxPages and maxItems do not apply: a batch reads to the last page. The method is always GET.
  • The checkpoint is the next page's position: the offset or page number, the API's token or cursor, or, for next-url and link-header, the next page's path and query. The query keys you set in query are removed from a stored next URL and set again on each request, so an API that echoes a key into its next link never puts it in the checkpoint. A stored next URL also drops any parameter whose value is one of the profile's secrets (API key, bearer token, password, client secret, the current access token) and any parameter named like a credential (api_key, apikey, access_token, token, key, client_secret, password), unless you set it in query. Signature parameters such as sig and signature are kept, since signed (SAS-style) next links need them. The profile's credentials are sent as headers on every request and are never stored.
  • A chunk ends inside a page when the page holds more items than the chunk has room for. The next chunk reads that page again and skips the items already queued, so the API must return a page's items in the same order each time.
  • The batch completes when there is no next page, or when the API returns the page just read again.
  • A next page on another host fails the batch. A 429, a 5xx, a timeout or a dropped connection is retried on the page first (waiting out Retry-After, up to a minute) and then from the checkpoint. Any other 4xx fails the batch. Errors name the endpoint, never the full URL or the response body.

Every SQL chunk is read in a READ ONLY transaction. BigQuery keeps a finished query's results for about a day, so resume a paused BigQuery batch within that time; after it, start a new batch.

Every row once

A chunk's executions and its checkpoint are written together, so a restart never loses a chunk and never queues one twice:

  • If the engine stops before the write, nothing of the chunk was stored. The next engine to pick the batch up reads the chunk again from the stored checkpoint.
  • Each row's execution id is derived from the batch and the row's position, so a chunk written twice still runs each row once.
  • One engine reads a batch at a time (a lease). If that engine stops, another takes over once the lease lapses, about a minute later.
  • A read that fails for a passing reason (a rate limit, a server error, a dropped connection or a timeout) is tried again from the checkpoint after a wait that doubles each time it fails again (30 seconds, then 1, 2, 4 minutes and so on, at most 15 minutes); the batch shows Retrying (attempt 2 of 8) with the error. After 8 failed attempts in a row the batch is failed with "Gave up after 8 read attempts". Any other failure (bad SQL, a denied credential, a chunk too large for one response) fails the batch. Fix the cause and Resume it: reading carries on from the checkpoint, and rows already queued are not queued again. Through the API, a resume can also lower the chunk size.

Progress and controls

Messages > Batches lists the workspace's batches with a progress bar and the counts:

CountMeans
ReadRows read and queued so far, out of the total when known.
QueuedExecutions waiting or running. Never more than the max backlog.
DoneExecutions that completed.
FailedExecution attempts that failed. A workflow retry runs as a new execution.

The controls:

  • Pause stops reading. Rows already queued still run.
  • Resume carries on from the checkpoint.
  • Cancel batch stops reading and cancels the queued rows. Rows already run stay as they are.

Each start, pause, resume and cancel is in the audit log (batch.started, batch.paused, batch.resumed, batch.cancelled), without the query or its values.

The API

bash
curl -X POST https://engine.example.test/api/batch-runs \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workflowId": "wf-encounters-backfill",
    "adapterProfileId": "warehouse",
    "params": { "sql": "SELECT id, family FROM encounters ORDER BY id" },
    "chunkSize": 1000,
    "maxBacklog": 5000
  }'

GET /api/batch-runs lists batches with their progress, and POST /api/batch-runs/{id}/pause, resume or cancel changes one. The workflow must be on, and a batch is licensed and PHI-checked like a manual run.

Reference