Transactional outbox on the producer side
Status
Section titled “Status”Accepted.
approx. 2026-05 (the outbox writers and relay are in the first weeks of the repository; the retry-forever and block-on-error behaviour below was added later and is current).
Context
Section titled “Context”An application that saves an order and then calls an HTTP API to announce it has two writes that can disagree. If the order commits and the process dies before the call, nobody hears of the order. If the call succeeds and the transaction then rolls back, the world hears of an order that does not exist. Retrying the call fixes neither.
The platform needs events to be true facts. Everything downstream, from subscriptions to ordering to audit, assumes that an event it holds describes a change that really happened and that no committed change is missing its event. The producers are applications in many languages and databases, and the platform cannot reach into their transactions.
Decision
Section titled “Decision”Producers write events into their own database, in the same transaction as the business change, and a separate relay delivers them.
- Each SDK and both application frameworks write rows to an
outbox_messagestable on the transaction or connection the application supplies. A row has a type (EVENT,DISPATCH_JOB,AUDIT_LOG), a payload, a message group (the ordering key) and a status. - A relay (
fcdev outboxnext to the application, or the platform’s own outbox subsystem for its database) claims pending rows, sends them in batches to the platform’s batch endpoints and deletes the ones accepted. - The relay never drops a row it could not deliver. Retryable failures (outages, timeouts,
5xx, authentication errors) are retried with no attempt limit and a backoff that doubles up to five minutes. Back-pressure (429) holds the group for the server’sRetry-Afterwithout counting as a failure. - A refusal (
400or403: the platform will never accept this row) stays in the table, and with block-on-error (on by default) blocks its message group so that later rows are not delivered ahead of it. The block is persisted in the row, so a restart cannot move the group past the refused row. - The batch endpoints answer one result per item, by position, so one bad item does not reject a batch of 100.
- Delivery is at-least-once. Events carry a deduplication id, which every SDK sets to the outbox row id by default, so a resend is not a second event. Dispatch jobs use an optional idempotency key.
- Ordering is per message group, kept inside one relay process, so there is one relay per outbox table.
- The platform’s own use cases write the same event and audit rows directly in their transaction; the platform is the destination and has no outbox to hop through.
Consequences
Section titled “Consequences”Good
- “Committed implies announced, rolled back implies not announced” holds without distributed transactions.
- Outages of the platform or the network cost latency, not data. Producers stay available while the platform is down.
- The wire between producer and platform is one simple batch protocol, the same in every language.
- Order within a group survives retries and restarts.
Bad
- Another moving part per producer: a table, a relay process and its credentials.
- At-least-once delivery means duplicates are possible on the wire, handled by deduplication ids.
- Latency is the poll interval (one second by default) plus the batch round trip.
- A refused row blocks its group until an operator unblocks or skips it. This is deliberate (skipping silently would reorder or lose events) but needs monitoring: a stuck group does not recover by itself.
- A relay reads only databases it supports: PostgreSQL and MongoDB are drained, and MySQL rows can be written by SDKs but no relay reads them today.
- The outbox table grows if the relay is down.
Alternatives considered
Section titled “Alternatives considered”- Call the platform from the request, then commit. Loses events or invents them on failure.
- Two-phase commit across the application database and the platform. Not available across organisations and databases, and too fragile.
- Change-data-capture on the business tables. Produces row-change events rather than business events, and requires database-level setup per producer.
- Publish to a broker directly from the application. Same dual-write problem with a different system.
- Give up after a retry limit and drop or dead-letter the row. The first implementation did this (three attempts). It was replaced because a long outage would silently lose events.