External Workers
External workers are the services that do the actual work for BPMN service tasks (and worker-mode send tasks, throw events and end events). The engine doesn't run task code itself - it dispatches jobs to a queue, and any service that can speak HTTP can pull from the queue, do the work, and report back.
This page is the worker-author guide: how the dispatch model works, what the HTTP endpoints look like, and how to monitor workers from the UI.
This tutorial writes a Spring Boot job worker for a service task, plus a review inbox for the process's user task.
How dispatch works
┌──────────────────┐ ┌──────────────────┐
│ Process instance │ service task │ External jobs │
│ reaches a node │ ───────────► │ queue (PENDING) │
└──────────────────┘ └──────────────────┘
│
│ long-poll
▼
┌──────────────────┐
│ Worker │
│ (any language) │
└──────────────────┘
│
complete ◄───┴───► error
│
▼
┌──────────────────┐
│ Process resumes │
│ (or boundary │
│ error fires, │
│ or instance │
│ gets incident) │
└──────────────────┘
A job is created when the engine reaches an element that needs external work - a service task with a quantum:taskDefinition, a send task in worker mode, or an intermediate throw or end event with a quantum:taskDefinition. The job carries the task type, the resolved input variables, the design-time headers, and an execution key that the worker uses when finalising it.
Workers select work by task type: each worker registers itself for one or more types (payment-worker, email-sender, etc.) and only sees jobs for those types.
Designing tasks for workers
The producing side of this is documented under Tasks. The fields that matter for the worker contract:
| Field | Notes |
|---|---|
quantum:taskDefinition type | The selector workers poll on. Required, without it deployment fails |
quantum:taskDefinition retries | How many error reports the engine accepts before surfacing the failure (see Failure handling) |
quantum:ioMapping inputs | Variables prepared before the job is created - the worker sees them in variables |
quantum:ioMapping outputs | Applied after the worker completes - extract fields from the worker's output back into the parent scope |
quantum:taskHeaders | Static design-time metadata passed to the worker alongside each job. Headers are not merged back into the instance |
The worker HTTP API
All endpoints live under the project: /projects/{projectID}/bpmn/external-jobs. Authentication is the same as the rest of the API - a bearer token in the Authorization header. For service-account tokens, see Authentication.
Poll for jobs
POST /projects/{projectID}/bpmn/external-jobs/poll
Long-polls for jobs of one task type. Returns a batch of jobs as soon as any are available, or 204 No Content once the timeout elapses with no work.
| Field | Required | Notes |
|---|---|---|
taskType | yes | The selector this worker handles |
clientID | yes | Stable identifier for this worker process. Used to attribute job locks, and named in the history entry and any incident of a job it reported or abandoned |
lockDuration | no | How long each acquired job stays locked to this worker without a heartbeat. Duration string (5s, 2m). Defaults to 30s, clamped to 10s..5m |
timeout | no | How long to wait before returning 204. Duration string. Defaults to 30s, capped at REST_WRITE_TIMEOUT minus 5 seconds (55s by default) |
maxJobs | no | Maximum jobs to acquire in one call. Default 1, capped at 100 |
Each returned job looks like this:
{
"executionKey": "002a-…",
"instanceID": "bpmn-002a-order-…",
"nodeID": "charge-card",
"taskType": "payment-worker",
"variables": { "order_id": "ORD-123", "amount": 49.95 },
"headers": { "currency": "USD" },
"retries": 3,
"status": "PENDING",
"lockedBy": "worker-eu-1",
"lockExpiresAt": "2026-05-02T12:34:56Z",
"createdAt": "2026-05-02T12:34:26Z"
}
The executionKey is the path parameter you'll use when finalising the job. The instanceID goes in the complete and error bodies.
curl -X POST "$API/projects/$PROJECT/bpmn/external-jobs/poll" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"taskType": "payment-worker",
"clientID": "worker-eu-1",
"lockDuration": "30s",
"timeout": "20s",
"maxJobs": 5
}'
Extend the lock (heartbeat)
POST /projects/{projectID}/bpmn/external-jobs/{executionKey}/heartbeat
Keeps the caller's lock on a job for another lockDuration, clamped like the poll's. The SDKs send it at half of the lock the poll granted (lockExpiresAt) while a handler runs, so a lockDuration above the 5m clamp still heartbeats in time. Other workers can't claim the job while the lock holds. One worker keeps a job for at most ENGINE_JOB_MAX_HOLD (30 minutes by default), however often it heartbeats.
| Field | Required | Notes |
|---|---|---|
clientID | yes | Must match the clientID that originally polled the job |
lockDuration | no | New lock window from now, up to the hold limit. Defaults to 30s |
A 409 with code CONFLICT means this worker no longer holds the job. Its lock ran out, another worker holds it, or the job already finished. The message says when the job was cancelled, so the work is no longer wanted. Stop working on it, because its result would be discarded. A 404 means no job has this execution key, which is also the answer once the job's instance has ended. Stop working on it too.
Complete a job
POST /projects/{projectID}/bpmn/external-jobs/{executionKey}/complete
Finalises the job successfully. The supplied variables are merged into the originating instance's scope and the process resumes after the service task.
| Field | Required | Notes |
|---|---|---|
instanceID | yes | The instance ID returned in the poll response |
clientID | no | The clientID that polled the job. When set, a worker that no longer holds the lock gets 409 and its result is discarded: its lock ran out, another worker holds or completed the job, or the job failed or was cancelled. The SDKs always send it |
variables | no | Output map. Goes through any output mappings declared on the service task |
curl -X POST "$API/projects/$PROJECT/bpmn/external-jobs/$KEY/complete" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"instanceID": "bpmn-002a-order-…",
"variables": { "transactionId": "txn-789", "approved": true }
}'
complete is idempotent on the execution key - a second call after success is a no-op, and a worker that completes its own job again gets 200. A complete and an error sent at the same time for one job are applied one after the other, so the second answers 409. Once the instance has ended its jobs are gone, and a complete or error on one answers 200 and changes nothing. A 404 means the instance is running and has no job with this execution key, for complete and error alike.
Fail a job (BPMN error)
POST /projects/{projectID}/bpmn/external-jobs/{executionKey}/error
Reports a worker-side failure with a BPMN error code. Depending on retryable and the job's retries, the job is offered again or the error code is raised as a BPMN error on the originating service task - see Failure handling.
| Field | Required | Notes |
|---|---|---|
instanceID | yes | The instance ID returned in the poll response |
errorCode | yes | BPMN error code, matched against any errorEventDefinition errorRef on the task's boundary handlers |
clientID | no | The clientID that polled the job. When set, a worker that no longer holds the lock gets 409 and its report is discarded, so it can't retry or fail a job it lost. The SDKs always send it |
retryable | no | true (default) uses the job's retries first, false raises the error code at once |
variables | no | Variables submitted alongside the error. Available to error-boundary handlers |
Batch endpoints
For high-throughput workers that pulled maxJobs > 1:
POST /projects/{projectID}/bpmn/external-jobs/batch/complete
POST /projects/{projectID}/bpmn/external-jobs/batch/error
Each request body wraps an items array. Per-item status is returned so a partial failure doesn't sink the whole batch:
| Item status | Meaning |
|---|---|
completed | The job was finalised successfully |
failed | The error was raised on the process, because no retries were left or retryable was false. An error boundary catches it, or it raises an incident |
requeued | A retry budget remained - the job is back in PENDING and is offered again after the retry delay |
error | The per-item operation itself failed, or this worker no longer holds the job. The job's state is unchanged |
Failure handling
When a worker calls error, the retryable flag decides what happens:
retryable: true(the default) is a technical failure. While the job has retries left (quantum:taskDefinition retries), the engine takes one off and offers the job again after the retry delay, 10 seconds by default. The process is not told. Once no retries are left, the error code is raised as a BPMN error on the producing activity.retryable: falseis a business outcome. The error code is raised as a BPMN error at once, without using retries.
A BPMN error raised on the activity fires a matching error boundary event on the activity (or up the scope chain), which routes the token through it. With no matching boundary it raises an incident, and the instance waits until someone fixes the cause and retries it.
retries="3" therefore means up to four attempts: the first one and three retries. The retry delay is one setting for the whole installation, ENGINE_JOB_RETRY_DELAY on a self-hosted deployment (see Engine settings).
When a lock runs out
A worker's lock runs out when no heartbeat arrives within lockDuration, because the worker crashed, hung or lost its network, or when one worker has held the job for ENGINE_JOB_MAX_HOLD. Either way the attempt counts as failed, like a retryable error. While the job has retries left, the engine takes one off and offers the job again after the retry delay. With no retries left the activity raises a JobLockLost incident whose message names the worker and the reason. No error boundary catches it, because a worker that went away is a technical failure, not a business outcome.
A poll that fails on the server, or whose worker disconnects before the answer arrives, unlocks the jobs it locked at once, without using up a retry. Only an answer the server sent and the network lost leaves its jobs locked until lockDuration runs out.
A task without a retries attribute has no retries, so a worker that dies in the middle of such a job raises an incident. Set retries on tasks whose workers may restart while they run, and stop workers cleanly so a deploy doesn't abandon running jobs.
Error codes the SDKs emit
The official SDKs (Go, Java, JavaScript, Python) split handler failures into two outcomes, both reported via the same error endpoint:
| Code | When the SDK emits it | Variables on the error |
|---|---|---|
| Any code you choose | Handler explicitly throws/returns BpmnError(code, vars?) | Whatever you passed |
WORKER_ERROR | Handler throws/returns any other exception, the variable decode step fails, or the handler panics | { "error": "<exception message>" }, message truncated to 2048 bytes (UTF-8 safe, configurable via the worker's MaxErrorMessageBytes / equivalent option) |
The SDKs send a BpmnError with retryable: false, so it reaches the process at once, and WORKER_ERROR with retryable: true, so it uses the retries first. The distinction is intent: BpmnError is a business outcome you expect the process to handle, WORKER_ERROR is an unexpected technical failure.
This means you can put a boundary error event on a service task whose errorRef names an error definition with errorCode="WORKER_ERROR", such as <bpmn:error id="worker_error" errorCode="WORKER_ERROR"/>, to react to infrastructure-level failures from the process side - for example, routing to a compensation path once retries are exhausted on a flaky integration. Catching it gives you the original message in the error variable for logging or diagnostics.
If you are writing a worker against the HTTP API directly without the SDK runtime, this convention only applies if you choose to follow it, the engine does not synthesise WORKER_ERROR on its own.
If the originating instance is cancelled while a job is in flight, the job goes with it. A later heartbeat answers 404, and a later complete or error answers 200 and changes nothing. A job cancelled while its instance keeps running, by an interrupting boundary event for example, moves to CANCELED with a cancelReason, and a later complete or error answers 409.
Worker design considerations
A few things that matter when you're writing a worker:
- Pick a stable
clientID. It's used to attribute locks and names the worker in history and incidents. A differentclientIDper process or replica is fine, per-poll randomness makes both useless. - Pick the lock duration for how fast a dead worker should be noticed. It is how long a silent worker keeps a job, not how long the job may take, because heartbeats keep a long job going. A shorter lock brings a crashed worker's job back sooner, but every heartbeat has to arrive within it.
- Hold the heartbeat in a separate task from the actual work. A heartbeat that waits on blocked work stops too, and the lock runs out while the work still runs. The SDKs heartbeat from their own goroutine, thread or coroutine.
- Stop workers cleanly. On shutdown the SDKs stop polling, let running jobs finish within a shutdown timeout and report them. Wire SIGTERM to the worker's stop, and give the pod a termination grace period longer than that timeout.
completeis idempotent onexecutionKey. If you crash between doing the side-effecting work and callingcomplete, a retry is safe.- Treat headers as configuration. They're set at design time and shouldn't carry per-instance values - that's what
variablesis for.
Operating workers from the UI
The BPMN Jobs view (in the BPMN navigation) is the live operator dashboard.
Queue depth
A bar per task type, width proportional to the largest pending count. Click a bar to filter the list to that type with status PENDING.
Watching workers
Whether workers keep up shows in the engine metrics on the /metrics endpoint,
labelled by project and task_type:
bpmn_engine_jobs_pending- jobs waiting for a worker.bpmn_engine_jobs_activated_total- jobs handed to workers by a poll.bpmn_engine_job_activation_wait_seconds- how long jobs waited before a worker took them.bpmn_worker_active- 1 for each worker polling a replica, with itsclient_id. A worker counts while a poll is open and for its poll timeout, at least 30 seconds, after the last one ended. A worker busy on its jobs with no free slot to poll for drops out until it polls again.
The workers polling each task type, counted once even when their polls reach several replicas:
count by (project, task_type) (max by (project, task_type, client_id) (bpmn_worker_active))
A task type with pending jobs and no worker polling for it is the stuck-queue signal to alert on:
max by (project, task_type) (bpmn_engine_jobs_pending) > 0
unless on (project, task_type) count by (project, task_type) (bpmn_worker_active)
See Enterprise operations for every engine metric.
Job list
Filterable table showing one row per job. It holds the pending jobs and the finished jobs of running instances. When an instance ends its jobs leave the list, and the instance's history keeps each job's task type, retries left and worker on the entry that ended the job.
| Column | Description |
|---|---|
| Task type | The selector for the job |
| Instance | ID of the originating instance |
| Node | The activity that produced the job |
| Status | PENDING, COMPLETED, FAILED, or CANCELED |
| Retries | Remaining retry budget |
| Locked by | The clientID currently holding the job |
| Created / Age | When the job was queued |
Click a row to expand it and see the cancel reason (cancelled jobs), lock expiry, input variables, and headers. The icon at the right of each row jumps to the originating instance.
Filters: time range (last hour / 24h / 7d, defaults to 1h to keep queries fast), task type, status, instance ID, business ID. The list auto-refreshes every 3 seconds while any visible row is PENDING.
Manual completion from the UI
For pending jobs, operators can complete or fail a job by hand from the instance detail run panel - useful when you're testing a process before there's a worker, or recovering from a stuck worker.
Test runs
A test run creates its jobs under the task type with the draft: prefix, so production workers never receive them. To work a test run's issue-payout jobs with a real worker, poll for draft:issue-payout. Queue depth leaves test-run jobs out, and the job list shows them only when filtered by their instance.
Related endpoints
| Endpoint | Use |
|---|---|
GET /projects/{projectID}/bpmn/external-jobs | Paginated list with taskType, status, instanceID, businessId (prefix match) and createdAfter filters. The Jobs view uses this, it's also the right thing to call from a custom dashboard |
GET /projects/{projectID}/bpmn/external-jobs/queue-depth | One entry per task type with at least one pending job |