Skip to content

Commit a1a9fbd

Browse files
committed
docs(webhooks): the HTTP dispatcher's idle tick is two reads, it wakes at the next due time, and dispatchSoleWriter / db.soleWriter skip the ramp (#29919)
Claude-Session: https://claude.ai/code/session_01Utp6CY2ugcVZ5KKbTbWpXw Co-authored-by: Claude <noreply@anthropic.com>
1 parent def0361 commit a1a9fbd

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

‎content/docs/automation/webhooks.mdx‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,39 @@ same partition — useful for in-order delivery and connection reuse. On a
452452
single-node runtime the lock is an always-grant stub.
453453

454454
Each tick opens with **one** visibility-timeout reap for the whole table —
455-
`in_flight` rows claimed longer than `claimTtlMs` ago return to `pending` — and
456-
then claims partition by partition, so a tick over an empty outbox costs
457-
`1 + partitionCount` statements. The loop **backs off while idle**: every tick
458-
that claims nothing doubles the delay to the next, from `intervalMs` (default
459-
500 ms) up to `maxIdleIntervalMs` (default 30 s; `dispatchMaxIdleIntervalMs` on
460-
`MessagingServicePlugin`), and a tick that claims work snaps it back.
461-
`messaging.enqueueHttp()` and `messaging.redeliverHttp()` wake the dispatcher
462-
running in the same process, so a delivery written there goes out at once. Work
463-
nobody announces — a retry coming due, a row another process wrote — is noticed
464-
within one backed-off interval, never more than `maxIdleIntervalMs` late.
455+
`in_flight` rows claimed longer than `claimTtlMs` ago return to `pending` — then
456+
asks once, across every partition, whether any `pending` row is due. Only when
457+
one is does it claim partition by partition. A tick over an empty outbox
458+
therefore costs **two** statements, both reads, whatever `partitionCount` is:
459+
the reap's "anything expired?" read (its UPDATE runs only when that finds a
460+
row) and the "anything due?" read.
461+
462+
The loop **backs off while idle**: every tick that claims nothing doubles the
463+
delay to the next, from `intervalMs` (default 500 ms) up to `maxIdleIntervalMs`
464+
(default 30 s; `dispatchMaxIdleIntervalMs` on `MessagingServicePlugin`), and a
465+
tick that claims work snaps it back. `messaging.enqueueHttp()` and
466+
`messaging.redeliverHttp()` wake the dispatcher running in the same process, so
467+
a delivery written there goes out at once.
468+
469+
The loop also **wakes at the next due time**. After the first empty tick of an
470+
idle stretch it reads, once, the earliest instant a row becomes claimable
471+
without anyone writing: the soonest future `next_retry_at`, or the moment the
472+
oldest `in_flight` claim passes `claimTtlMs`. It never sleeps past that
473+
instant, so a retry is attempted when it comes due and a crashed node's claim is
474+
recovered when its TTL passes, whatever the ceiling. That costs two more reads
475+
at the start of each idle stretch, not one per tick. The backoff is left with
476+
one job: a row **another process** wrote, which is noticed within one
477+
backed-off interval, never more than `maxIdleIntervalMs` late.
478+
479+
On a host where no other process writes these tables, that job is empty. Set
480+
`dispatchSoleWriter: true` on `MessagingServicePlugin` there, for example on a
481+
hosted tenant kernel with one kernel per tenant database. An empty tick then
482+
sleeps straight to the next due time or the ceiling, instead of re-running the
483+
ramp from `intervalMs` after every boot and every burst, and a fresh kernel's
484+
dispatchers tick once in their first minute. The job queue takes the same flag
485+
as `DbQueueAdapter`'s `soleWriter`, set through `QueueServicePlugin`'s
486+
`db.soleWriter`. Leave both off when a second node or a worker process writes
487+
the same database. Default: off.
465488

466489
Within a held partition, the lock-holder claims a batch with an **atomic
467490
conditional UPDATE** rather than `SELECT … FOR UPDATE SKIP LOCKED`:
@@ -697,7 +720,7 @@ A precise table of what the runtime promises and what it does not.
697720
|------------------------------------------|-------------------------------------------------------------|
698721
| Producer node crashes mid-emit | **Not durable today.** The realtime bus (`InMemoryRealtimeAdapter`) is an unpersisted, in-process pub/sub — an event lost before Stage 3's INSERT is gone, not redelivered (see §4.1). |
699722
| Subscriber node crashes after persist | Row exists in `sys_http_delivery`, another node picks it up. |
700-
| Dispatcher node crashes mid-HTTP | Row stays `in_flight` with `claimed_by`; the first dispatcher tick after the claim TTL reverts it to `pending` and it is re-posted. The TTL derives from the dispatcher tick (`intervalMs`, default 500ms): `lockTtlMs = 5 × intervalMs`, `claimTtlMs = 2 × lockTtlMs` (so ~5s at defaults), all configurable via `HttpDispatcherOptions`. An idle surviving dispatcher ticks at least every `maxIdleIntervalMs` (default 30s), so recovery takes at most `claimTtlMs + maxIdleIntervalMs` (~35s at defaults). |
723+
| Dispatcher node crashes mid-HTTP | Row stays `in_flight` with `claimed_by`; the first dispatcher tick after the claim TTL reverts it to `pending` and it is re-posted. The TTL derives from the dispatcher tick (`intervalMs`, default 500ms): `lockTtlMs = 5 × intervalMs`, `claimTtlMs = 2 × lockTtlMs` (so ~5s at defaults), all configurable via `HttpDispatcherOptions`. An idle surviving dispatcher wakes when the oldest claim it read at the start of its idle stretch passes its TTL, and ticks at least every `maxIdleIntervalMs` (default 30s) in any case, so recovery takes about `claimTtlMs` for a claim it saw and at most `claimTtlMs + maxIdleIntervalMs` (~35s at defaults) for one made after that read. |
701724
| A send outlasts the claim TTL and another dispatcher re-claims the row | The re-claiming dispatcher posts the delivery again (at-least-once — the receiver can see it twice; see the last row). The first dispatcher's late outcome is **not** written over the live attempt: its ack carries the claim credential (`claimed_by`, `claimed_at`) its claim stamped, the conditional update matches nothing, and it logs `http-dispatcher: ack refused, claim no longer held`. The row records the outcome of the attempt that still holds it. |
702725
| Receiver returns 5xx | Retry per backoff schedule until the fixed 8-attempt budget is exhausted (§4.5). |
703726
| Receiver returns 4xx | Treated as terminal — no retry, status `dead` immediately. Exception: 408 / 429 are retried. |

0 commit comments

Comments
 (0)