Skip to main content

Batch Operations

A batch operation applies one action to every workflow in a domain that matches a visibility query. You can terminate, cancel, signal, replicate or refresh thousands of workflows with one request, control how fast the batch runs, and stop it if the query turns out to be wrong.

Batch operations are managed through the BatchAPI, a gRPC service on the Cadence frontend, and the cadence batch CLI commands. For why the BatchAPI was built and how the access check changed, see Securing Batch Operations.

How it works​

When you start a batch, the frontend checks that you are allowed to act on the target domain, then starts a built-in batch workflow in the cadence-batcher system domain on your behalf. The batch workflow scans the workflows that match your query, page by page, and applies the operation to each one, limited by the RPS and concurrency you set.

The start request returns as soon as the batch is accepted. Use describe or list to follow its progress.

Requirements​

  • Server: v1.4.6-prerelease05 or later for all five BatchAPI calls.
  • CLI: v1.4.6-prerelease06 or later for all five cadence batch commands.
  • gRPC: The BatchAPI is gRPC only. The CLI commands always use gRPC, so --address must point at the frontend's gRPC port.
  • Advanced visibility: The batch scans workflows with a visibility query, and list filters batches by search attribute, so the cluster needs advanced visibility (for example Elasticsearch or OpenSearch).

Key concepts​

Operations​

OperationWhat it does to each matching workflowExtra parameters
TerminateTerminates the workflowNone
CancelRequests cancellation of the workflowNone
SignalSends a signal to the workflowSignal name (required), signal input (optional)
ReplicateResends replication tasks for the workflowSource cluster and target cluster (both required)
RefreshRefreshes the workflow's tasksNone

Batch ID​

Every batch has an ID that is unique within its domain. You can choose it, or let the CLI generate a random one. Starting a batch again with the same domain and batch ID while that batch is running returns the existing batch instead of starting a second one, so a start is safe to retry.

States​

StateMeaning
RunningThe batch is still applying the operation.
CompletedThe batch finished going through the matching workflows. Some workflows can still have failed. describe shows errorCount while the batch runs.
FailedThe batch itself failed or timed out.
StoppedThe batch was stopped before it finished.

Limits​

LimitDefaultMeaning
rps50Maximum operations per second across the whole batch.
concurrency5Number of workflows processed in parallel. RPS still caps the combined rate.
pagesize1000Number of workflows fetched per visibility page.

rps and concurrency can be changed while the batch runs. The page size is fixed at start.

Progress and starter​

describe returns totalEstimate, successCount and errorCount while the batch runs, and startedBy, the identity of the caller who started it. The starter is stored in the Operator search attribute, and list returns it too.

Access control​

Each BatchAPI request names the domain it acts on, and the frontend authorizes it against that domain like any other domain API. All five calls need write access to the target domain. The caller does not need access to cadence-batcher.

The check runs on each BatchAPI call, including the start. Once a batch is running, it does not limit what the batch workflow can reach.

note

The older cadence workflow batch commands start the batch workflow in cadence-batcher directly, so they are checked against cadence-batcher, not the target domain. They still work. Restrict access to cadence-batcher if you want every batch to go through the domain check.

CLI reference​

All commands take the global --domain flag for the target domain.

Start a batch​

cadence --domain <domain> batch start <operation> --query "<query>" --reason "<reason>" [flags]

<operation> is one of terminate, cancel, signal, replicate or refresh.

FlagApplies toDescription
--query, -qAllRequired. Visibility query selecting the workflows.
--reason, --reAllRequired. Why the batch is being run.
--batch_idAllBatch ID. Defaults to a random ID.
--rpsAllMaximum operations per second. Default 50.
--concurrencyAllWorkflows processed in parallel. Default 5.
--pagesizeAllWorkflows fetched per visibility page. Default 1000.
--yesAllSkip the confirmation prompt.
--signal_name, --snsignalRequired. Name of the signal to send.
--input, --insignalSignal input.
--source_cluster, --screplicateRequired. Cluster to replicate from.
--target_cluster, --tcreplicateRequired. Cluster to replicate to.

The CLI first counts the matching workflows and asks you to confirm, unless you pass --yes.

# Terminate stuck workflows at 2 operations per second
cadence --domain cadence-samples batch start terminate \
--query "WorkflowType = 'order-workflow' AND CloseTime = missing" \
--reason "cleanup after release" \
--batch_id release-cleanup \
--rps 2

# Signal every open workflow of a type
cadence --domain cadence-samples batch start signal \
--query "WorkflowType = 'order-workflow' AND CloseTime = missing" \
--reason "notify open orders" \
--signal_name refresh-prices \
--input '{"source": "batch"}'

List batches​

cadence --domain <domain> batch list [--state running|completed|failed|stopped] [--pagesize 100]

Prints one row per batch with its ID, state and starter. --pagesize sets the page size of each ListBatchOperations call. The CLI fetches every page.

Describe a batch​

cadence --domain <domain> batch describe --batch_id <batch-id>

Prints the state, limits, progress, reason, starter, and start and close times as JSON.

Update a running batch​

cadence --domain <domain> batch update --batch_id <batch-id> [--rps <n>] [--concurrency <n>]

Set at least one of --rps or --concurrency to a positive value. A value you leave unset keeps its current setting. The running batch picks up the new values shortly after, so describe can show the old values for a moment.

Stop a batch​

cadence --domain <domain> batch stop --batch_id <batch-id> [--reason "<reason>"]

Stopping a batch does not undo work it already applied.

Limitations​

  • Operation and query are not returned. describe does not return the operation or the query a batch was started with.
  • Progress is only reported while running. After a batch finishes, describe no longer returns progress.
  • Older batches are not listed. list only returns batches started through the BatchAPI. Batches started with cadence workflow batch do not appear.
  • Stop does not roll back. Use reset if you need to roll workflows back.