AWS SQS
The queue-backed transport on AWS SQS. Same RemoteTask/StepResult contract as BullMQ — tasks go to a per-group queue, results return on a shared queue — so Node and Python workers interoperate.
@dudousxd/nestjs-durable-transport-sqs carries steps over AWS SQS — the same role as the
BullMQ transport, for teams already on SQS instead of Redis.
pnpm add @dudousxd/nestjs-durable-transport-sqs @aws-sdk/client-sqsHow it compares to the other transports, and what SQS doesn't support: see Choosing a transport.
How it works
Say a checkout workflow calls the payments.charge-card step on an un-partitioned deployment. The
task routes to a queue named after the step itself, so a worker registers under that same name to
consume it:
// @Step({ name: 'payments.charge-card', … }) on a provider method
const { chargeId } = await ctx.step(this.payments.chargeCard, { orderId, amountCents });With the default durable prefix, that one call moves three messages across two queues:
- Dispatch → the engine sends the
RemoteTaskJSON to the step's own tasks queue,durable-tasks-payments.charge-card(<prefix>-tasks-<name>[@<partition>]). One queue per step name, so apayments.refundworker never seespayments.charge-cardtasks. - Run → a worker registered for that name long-polls
durable-tasks-payments.charge-card, runs itspayments.charge-cardhandler, then sends theStepResultJSON to the shared results queue,durable-results(<prefix>-results) — every worker replies on the same one. - Resume → the engine long-polls
durable-results, matches the result to the suspendedctx.stepbystepId, checkpoints it, and the workflow continues. Eight receive loops per instance each hand every message of a receive to the engine at once, so a wide fan's results are settled in batches; a message is deleted only after its result is written. A step fan's tasks are sent ten perSendMessageBatch.
engine ──RemoteTask──▶ durable-tasks-payments.charge-card ──poll──▶ worker
▲ │
└────────── poll ────── durable-results ◀──StepResult────────────────┘// resolves durable-tasks-<name> + durable-results by name (auto-creates them if autoCreate)
new SqsTransport({ client: new SQSClient({ region: 'us-east-1' }), autoCreate: true });const transport = new SqsTransport({ client, group: 'payments.charge-card' });
transport.handle('payments.charge-card', async ({ orderId, amountCents }) => ({
chargeId: await charge(orderId, amountCents),
}));group is the queue token this instance polls — set it to the exact step name it serves (suffixed
@<partition> if the deployment routes that step to a partitioned worker pool). Handling a second step name needs a second
SqsTransport instance with its own matching group; each instance polls exactly one queue.
Reusing queues you already provisioned? Skip name resolution by passing their URLs directly:
new SqsTransport({
client,
group: 'payments.charge-card',
taskQueueUrl: () => 'https://sqs.us-east-1.amazonaws.com/1234567890/orders-charge-card',
resultsQueueUrl: 'https://sqs.us-east-1.amazonaws.com/1234567890/orders-results',
});SQS is at-least-once — a task whose worker crashes before deleting it is redelivered after the visibility timeout — so keep handlers idempotent.
A message that fails to process — a result handler that throws, a result send that fails, a body
that isn't JSON — is reported through onError and left on the queue: SQS redelivers it after
its visibility timeout, and the poll loop carries on with the next message. Give the queues a
redrive policy
(maxReceiveCount → a dead-letter queue) so a message that keeps failing is moved aside instead of
retried forever.
Client
Pass an existing SQSClient via client (recommended — reuse the app's, already configured with
retries/region/credentials). Omit it and pass clientConfig instead (e.g. { region, endpoint, credentials } for pointing at ElasticMQ in dev) to let the transport build its own client — which it
then owns and destroys on close(). A client you pass in is left alone.
Sharing a queue with a non-durable consumer
Set marker to have every durable message carry that SQS message attribute, and have the poller
skip (release, don't delete) messages that lack it. That lets a queue already used by a
legacy/non-durable consumer be shared, as long as that consumer likewise ignores durable-tagged
messages. Leave it unset for the common case: a queue dedicated to durable traffic.
Worker health
SqsTransport doesn't implement groupHealth/listWorkerGroups either — the engine's
workerHealth() query, and the dashboard/Telescope worker-health panels built on it, return
empty for this transport's groups; only a groupHealth-capable transport (BullMQ) returns
non-empty results. Liveness here is the visibility timeout, not a queryable heartbeat: a message
whose worker crashes before deleting it becomes visible again after visibilityTimeoutSec, and
SQS's own redelivery is the recovery mechanism.
Run queue
The engine queues the runs it starts on <prefix>-runs (<prefix>-runs-<namespace> for an engine
scoped to a namespace), ten per SendMessageBatch, and every driving instance receives from it, at
most 256 runs in flight, extending a message's visibility while its run is in flight. SQS is
at-least-once and does not deduplicate a waiting run, so a run may be delivered twice; the engine
skips one that is no longer due. A FIFO queue (.fifo) gets one message group per run. Point it at
an existing queue with runsQueueUrl, or let autoCreate create it.
Options
| Option | Description |
|---|---|
client | An @aws-sdk/client-sqs SQSClient. Used instead of clientConfig when set. |
clientConfig | Used only when client is omitted — e.g. { region, endpoint, credentials } for ElasticMQ. |
group | The queue token this instance serves — required to register handle()s; must match the dispatched step's sanitized name (+ @partition, if set). |
prefix | Namespaces the fallback <prefix>-tasks-* / <prefix>-results names. Default durable. |
autoCreate | Create the by-name queues (durable-tasks-<group>, durable-results) if missing. Ignored for queues you supply via taskQueueUrl / resultsQueueUrl — those must already exist. |
runsQueueUrl | (namespace) => url: the run queue to use instead of resolving <prefix>-runs by name. See Run queue. |
taskQueueUrl / resultsQueueUrl | Reuse existing queues instead of resolving by name (a literal URL or a resolver). A taskQueueUrl resolver is called once per group and cached. |
marker | SQS message attribute tagging durable messages, so a queue can be shared with a non-durable consumer. See above. Unset by default. |
waitTimeSeconds | Receive long-poll seconds (0–20). Default 20. |
visibilityTimeoutSec | Visibility timeout for a received task, in seconds. Default 60. Every message of a received batch (the one running and the ones waiting behind it) is re-extended every third of this, so a step may run longer; a crashed worker's messages reappear after at most this long. |
onError | Where a failing receive, result handler, result send or non-JSON body is reported. Default console.error. |
The message body is the documented RemoteTask / StepResult JSON — identical to BullMQ — so a
Python worker on the same queues interoperates.
BullMQ / Redis
The queue-backed transport for cross-process and cross-language steps. Each step name gets its own tasks queue; results return on a shared results queue. Run one instance engine-side, one per worker.
SQL (database)
A broker-less, DBOS-style transport — dispatched steps are rows in the database you already run. Workers claim tasks with SELECT … FOR UPDATE SKIP LOCKED. The table + claim contract is documented so Node and Python workers share it.