Delivery guarantee

Delivery guarantee

Steps run at least once, messages go out at most once. How the engine claims each copy, what happens on failures and retries, and why journeys err on the side of a lost nudge over a duplicate.

Two guarantees meet in every journey. The durable runtime underneath (Cloudflare Workflows, Lambda durable functions, or the Node host's own runs) executes each step at least once: a process that dies between a step's effect and its checkpoint runs the step again. A message, on the other hand, should reach a person at most once: a duplicate marketing email is worse than a missing one. This page explains how the engine gets the second guarantee on top of the first, what every failure turns into, and the one place you can choose differently.

At most once, by a claim

Each copy of a message (one email, or one push to one device) goes through one durable step:

  1. The copy's row is recorded.
  2. The copy is claimed: message.claimed_at is written and committed before the send.
  3. The transport takes it.
  4. The result is settled: delivered_at, or an undelivered_reason.

When the step is replayed:

  • A settled copy is skipped.
  • A copy that failed in a way another attempt can fix had its claim released, so the retry sends it. That is a provider answering 429 or 5xx, or a sender that never got as far as asking (a token that expired, an exchange that timed out).
  • A copy refused for good is settled undelivered under the refusal's reason, and the journey goes on.
  • A copy claimed but not settled is treated as possibly delivered and is not sent again. The run that claimed it died between the transport taking the copy and the result being recorded, so nobody knows whether it went out. The engine logs a warning with the idempotency key, settles the copy as unconfirmed and moves on.

Each copy has an idempotency key, <instanceId>:<nodeId> (plus the device token for a push), stable across replays and retries. It is how the engine recognizes a copy it has already claimed.

The claim lives in the reporting store, a column of the message table in your Postgres. Without a reporting store there is no record between two runs of a step, and a replay sends again.

A request with no answer is not a refusal

The connection dropped, or the fetch timed out after the request left: the provider may have taken the message, and a second attempt would be a second message. The senders that cannot de-duplicate (SES, the Cloudflare Email REST API, FCM, the Slack and Discord webhooks) throw an UnansweredSendError for this case. The engine keeps the claim, settles the copy as no_answer, and goes on to the next step. Nothing is retried.

A failed fetch does not say whether it failed before or after the request left, so a connection that could not be opened is treated the same way, and that copy is lost. APNs and Web Push are retried as usual, because a repeat collapses on the device (APNs by apns-collapse-id, Web Push by Topic, both derived from the idempotency key). A 2xx whose body cannot be read counts as delivered: the status is the answer.

A refusal ends the copy, not the journey

When no attempt would go differently (a PermanentError, or a transport error marked not retryable: the provider refused this token, this address or this payload, or the channel is not configured), the copy is settled undelivered under the refusal's reason, an error is logged with the provider's answer, and the journey continues to the user's other devices and the next step.

The reason is the provider's own code where it gave one (BadTopic, THIRD_PARTY_AUTH_ERROR, PayloadTooLarge, SES's MessageRejected), Refused<status> for a bare status, bad_credentials or not_configured for a secret that is malformed or missing, and refused for an error that names none.

So one rejected address, or one template whose push is too large, costs that copy only. So does a deployment-wide mistake such as a wrong APNs key: the journeys keep running, the later steps send once it is fixed, and the cost shows up as the count of that reason in the delivery report. Watch that report, because no instance fails for it.

What does fail the step is the workflow itself being wrong: a template refusing its props or its content. That is not about the recipient, and retrying would not help.

Every outcome, at a glance

What happenedThe copyRetriedThe journey
Delivereddelivered_atnogoes on
Provider answered 429 or 5xx, or a token expiredclaim releasedyeswaits for the retry
Refused for good (address, token, payload, config)undelivered, provider's reasonnogoes on
No answer from a sender that cannot de-duplicateundelivered, no_answernogoes on
Claimed, then the run died before settlingundelivered, unconfirmednogoes on
User opted out of the topic or the channelskippednogoes on
Email with no addressundelivered, no_recipientnogoes on
Push with no deviceskippednogoes on
Template refuses its props (a required field missing)not sentnofails at that step

no_answer and unconfirmed are reasons like any other, so what at-most-once costs is counted in the delivery report rather than hidden.

A transport of your own takes part by what it throws: a reason string on the error names the refusal, retryable: false or a PermanentError marks it permanent, and unanswered: true (or UnansweredSendError, or the awaitAnswer helper, all from sendwend/engine) marks a request that got no answer. The Cloudflare send_email binding is not covered: what it throws is taken as a refusal and retried.

Why at most once

Exactly once is not available. Cloudflare Email Service accepts no idempotency key or client message id: the send_email binding takes the addresses, subject, body, headers and attachments and returns a server-generated message id, and the REST endpoint is the same. SES has no idempotency key either. FCM does not de-duplicate. Only APNs and Web Push collapse a repeat, on the device.

Between the two options left, at most once is the one for journeys. A duplicate marketing email costs spam complaints, unsubscribes and sender reputation. A lost nudge is invisible to the user, and the journey has later steps. Customer.io and Braze behave the same way: the delivery record is the source of truth, nothing is resent on uncertainty, and frequency caps sit on top.

The losses are narrow: a copy is lost only when a process dies in the moment between handing it to the transport and recording the result, or when a sender that cannot de-duplicate gets no answer.

Opting into at least once

Some messages must arrive: a receipt, a dispute notice, a reply the user is waiting for. For those, a duplicate is a nuisance and a missing copy is a failure. A template opts into at-least-once with redelivery: 'resend':

ts
emailTemplate({
  id: 'dispute_opened',
  transactional: true,
  redelivery: 'resend', // a duplicate is a nuisance here; a missing copy is a failure
  // ...
});

redelivery ('skip' by default) exists on every template kind: email, push, Slack and Discord. With 'resend', a copy that was claimed but never settled is sent again on replay. A send that fails for sure (the transport throws, a 5xx, a 429) is retried whatever this option says. On APNs and Web Push a resent copy still collapses on the device; FCM has no such header.

The default is a deliberate product decision, taken after reviewing provider-side de-duplication, a shorter claim window and resending with a dedupe header. Set redelivery: 'resend' on the templates that need it rather than expecting the default to change.

Custom actions run at least once

A custom action has no claim: it runs inside a durable step and is retried when it throws. It can therefore run more than once for one journey. Pass ctx.idempotencyKey to any external side effect so the other side drops the duplicate, as you would with any webhook handler.

Give each event an id

The guarantees above are about what goes out. The same care applies to what comes in. An event's id is the occurrence's identity for that user, and sending the same id twice records it once:

ts
await journeys.ingest({
  userId: 'u_123',
  events: [
    { event: 'purchase', payload: { value: 49 }, id: 'order-8841-confirmed' },
  ],
});

This matters because every count and window in a condition reads the event log. A second copy of one purchase silently changes what performed(e.purchase, { count: 2 }) decides, and a redelivered trigger event could start another journey.

Only the sender knows whether two deliveries describe one occurrence or two, so the engine never guesses. An event that arrives without an id is given a fresh one and recorded as its own occurrence. If your code may retry a request, send an id you can reproduce, and the retry costs nothing.

  • Use something that identifies the occurrence, not the event name: a row id from your own system, an upstream webhook's delivery id, a message id from your queue.
  • The id is scoped to the user (the unique key is (user_id, event_id)), so two users may reuse one id without one losing their event.
  • A redelivered trigger event (same id) enters at most once, in every re-entry mode.
  • Events emitted by .sendEvent() already carry the node's identity within the running instance, so a retried emit is recorded once.