Delivery guarantees
At least once, no ordering. What a successful publish promises, how retries work, and how endpoint changes affect queued work.
The rules
- Accepted means stored. When
publish()returns, the event and its recipients are committed, or written in your transaction and committed when you commit. - At least once. A receiver may get the same event more than once.
- No ordering. Retries, parallel workers, and replays all reorder events.
- Recipients are fixed at publish. Subscription changes affect later events only.
- Endpoint state is read fresh. URL, secrets, and pause or delete take effect at the next attempt.
Receivers handle rule 2 by processing each event.id once. Rule 3 needs a version check.
Order usually matters within one entity, such as one invoice. A retry of an older event can arrive after a newer one succeeded, and a replay can arrive days later. Put a version number or an updated-at time for that entity in data. The envelope's occurredAt is assigned when the event is published, not when the change happened, so it works as a version only when one place publishes all of an entity's events. Apply an event only when its version is newer than the one you stored. Otherwise answer 2xx and skip it. Run the check in the same transaction as the receipt table, so a repeated or stale event leaves the invoice unchanged:
INSERT INTO invoices (id, amount, version) VALUES ($1, $2, $3)
ON CONFLICT (id) DO UPDATE SET amount = excluded.amount, version = excluded.version
WHERE invoices.version < excluded.version;Retries
A delivery is pending until a worker sends it (in_flight), then ends succeeded, failed, or cancelled (the endpoint was deleted). Each attempt's response decides what happens next:
| Response | Result |
|---|---|
2xx | succeeded |
410 | failed, no retry |
| Any other status | Back to pending |
| Network, DNS, or timeout error | Back to pending |
410: by default the endpoint is also paused.- Any other status: this includes
3xxand4xx. Redirects are never followed. - Back to
pending: the delivery waits until the next retry time.
By default a delivery gets up to eight attempts over about 28 hours, so a receiver whose owner fixes it the next day still gets the event:
| Attempt | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Waits | now | 5 s | 5 m | 30 m | 2 h | 5 h | 10 h | 10 h |
Change it with retry: { delaysMs, maxAgeMs } on createWebhooks() or createDelivery(). A 429 or 503 with a longer Retry-After header waits that long instead, within retry.maxAgeMs (48 hours by default). The retry window counts from the delivery's creation, or from its first attempt after a pause, so a delivery held behind a paused endpoint gets its full window again after the resume. A running worker clears the window when it finds the endpoint paused, so a delivery that no worker looks at during the pause ages as it would without one. retentionMs still bounds it. Every retry keeps the event ID and body and gets a fresh timestamp and signature.
Automatic pauses
The worker pauses an endpoint when all its attempts have failed for five days, or when it answers 410 Gone. Its queued deliveries wait as for any pause, and its pauseReason says why. Resuming it, editing it, or one successful attempt restarts the five-day period. Use the onEndpointPaused hook to tell the owner, and see automatic pauses for the options.
Publication
matchRecipients() runs once, when you publish. It returns every subscribed endpoint in the scope, paused ones included, and the list is stored with the event.
- If endpoint management can't be reached,
publish()throws. An outage never turns into "no recipients". - Endpoint edits made at the same moment may or may not be seen. There is no scope-wide snapshot.
- A repeated
idempotencyKeyreturns the original event without looking up recipients again, even if management storage is down. - Inside your transaction, only delivery storage joins the commit. A Better Auth or second-database write does not.
Endpoint changes while work is queued
| Change | Effect on queued deliveries |
|---|---|
| Pause | Held until resume |
| Automatic pause | Same as a pause |
| Resume | Eligible deliveries send again |
| Delete | Pending work cancelled |
| Change URL | Next attempt uses the new URL |
| Change subscriptions | Later events only |
| Rotate signing secret | Signs with current secrets |
- Pause: the retry window restarts at the first attempt after the resume, within
retentionMs.- The reset happens only when a running worker finds the endpoint paused while the delivery is due, and otherwise the old window stays and can expire after the resume.
- Delete: pending work is cancelled when the worker sees it. Secrets are cleared.
- Change subscriptions: already accepted recipients stay.
- Rotate signing secret: the next attempt signs with the current secrets (both, during the overlap).
A request already being sent when you pause or delete can still arrive. If endpoint management is unreachable at attempt time, the delivery waits without using up an attempt. An outage is never treated as a deletion.