Skip to main content

Components

How a delivery flows

1

Publish (route events, inside the request)

Every route that goes through the shared handler()/ok() wrapper calls publishApiTransactionEvent after a 2xx. The publisher derives the catalogue internal from the method and route, then checks the in-memory set of internals that currently have at least one active subscriber. If nobody listens, nothing is enqueued — the queue tables stay empty for the thousands of mutations no one subscribed to. Failures here are logged and never surface to the API caller. The message names the record (a hint of the route, else the id in the URL, else data.document_id of the response) and, when the request already knows it, its owner.
2

Publish (system events, where the fact happens)

Facts that no request produces are published by the code that records them: the repository that moves a payment to authorized, the handler that activates a contract after its last signature, the scheduled job that expires a coupon. It calls publishSemanticWebhookEvent after the write, behind the same flag and the same subscriber check, and it never throws. A change made by a SQL function is published by the TypeScript code that calls it. See System publisher.
3

Route (webhook-out-route)

The consumer loads the catalogue row, resolves the owning account of the record when the publisher did not know it (see below), and selects the matching webhooks: global ones always match; account-scoped ones match only when the resolved account equals the webhook’s account. For the first match it builds, once, what every delivery of the event will carry: the data.object of the record and a snapshot of the owner without its identity document. One webhook_dispatch row is inserted per match with status = pending, then one webhook-out-deliver message is sent per row.
4

Deliver (webhook-out-deliver)

The consumer reads the owning account (country, identity document, document type), builds the body, signs it with the subscriber secret, POSTs it with a 10 s timeout and redirect: "error", and records the outcome (success, error with next_retry_at, or exhausted) on the ledger row. Retryable failures are rescheduled on the custom backoff schedule; see Retries and failures.

Owning-account resolution

Account-scoped subscriptions need to know which account a record belongs to, and every delivery names that account in data.account. The catalogue records one strategy per event: Rules behind the table:
  • Two-account resources resolve to the tenant that contains them. A membership belongs to its organization, not to the member; a signer belongs to the customer of the contract, not to the person who signs; a merge belongs to the account that survives; a plan licence belongs to the account that pays the subscription; a Club coupon assignment belongs to the merchant.
  • A payment resolves through its debt first, then through its payment method: a payment recorded with a system payment method still belongs to the customer who owed the debt.
  • session is never a fallback. Staff acting on a customer’s record does not own it; only the routes that act on the caller’s own data use the session.
  • A person’s own data never reaches the employer. The account/me routes, the inbox and the notification preferences change the person, so an employee’s profile, logins or deletion are scoped to the personal account even while an organization is active. A company created from account/me/company belongs to the new company, and a confirmed account/me/merge to the account that survives.
  • Staff, reference and batch records stay none: internal alerts, the staff organization chart, short links, enterprise signers, catalogues, platform configuration and batch triggers never belong to a customer account.
  • Soft-deleted rows still name their owner. The resolver reads rows without filtering deleted ones, which is what scopes a *.deleted event.
The resolver runs once per event, on the route stage; deliveries never touch the source table again.

Deletes and purges

A delete answers an empty body, so the publisher takes the id of the record from the URL (/x/{id}, /x/{id}/active, /x/{id}/purge, /x/{id}/<action>). A purge removes the row, so there is nothing left to resolve afterwards: the request wrapper reads the owner before the route handler runs and hands it to the publisher. That read only happens for a DELETE …/{id}/purge of an account-scoped resource with an active subscriber, is bounded to 1.5 seconds and never fails the purge. When it cannot answer in time the event goes to global subscribers only.

System publisher

publishSemanticWebhookEvent({ internal, resourceId, account?, actorUser?, discriminator?, occurredAt?, correlation }) enqueues the same webhook-out-route message as the HTTP publisher, with no method, path or route.
  • Where it is called. At the choke point of each fact — the one repository or service every code path goes through to make that transition — rather than in each queue consumer, cron and webhook handler that can trigger it.
  • Deterministic id. The message id is webhook-out:<internal>:<record id>, or a digest of the record id and a discriminator when the fact can repeat on the same record (the payment that paid a debt, the status a payment method moved to). A retry, a provider redelivery or two code paths that reach the same state route the event once, and the route stage reuses the dispatch it already wrote.
  • No outbox. The event is published after the write, not in the same transaction. If the process dies in between, the event is lost. This is an accepted limit: delivery of a system event is at most once per fact, and the REST API remains the source of truth.

What a delivery is built from

Two consequences follow from that split:
  • data.object is frozen, data.account is live. Every retry and replay of a delivery carries the same object, and the owner as it is when that attempt is sent.
  • The identity document never rests in the pipeline. It is read into the signed body and nowhere else: not in the webhook_dispatch row, not in a queue message, not in a log line. What the ledger keeps is the id of the owner and a snapshot of its type, country and document type, which is what a delivery carries (with dni: null) if the account no longer exists. A subscriber URL that is not HTTPS receives dni: null.

Lanes and schedule

Both topics run on the dedicated webhook-out lane (vercel.json → app/api/queue/consumers/webhook-out/route.ts) so a burst of deliveries cannot starve business jobs, and business backlogs cannot delay a subscriber’s notification. The deliver topic uses a custom retry schedule instead of the platform default — the subscriber-facing backoff is part of the public contract.

Feature flag

Publishing is gated by the server flag platform-webhook-out-publishing (it replaced ENABLE_API_EVENT_QUEUE in 2026.11.2; the variable is only a transitional fallback until 2026.11.3). While it is false the API behaves exactly as before: no catalogue lookup, no cache, no queue traffic. Operators flip it per environment in Horizon Enterprise → Capabilities, without a deploy, after the catalogue is synced and the first subscriber has been tested; see Operations.
Since api_version 2026-11-15 the body carries personal data (the identity document of the owning account) and the record itself. It is still a notification: data.object is the state when the event was routed, events are not ordered and a system event can be lost. Read the resource through the API with the subscriber’s own credentials whenever the latest state matters.