Skip to content

Outbox processor

The outbox processor (also called the outbox relay) drains a producer’s outbox_messages table and posts each row to the platform’s batch endpoint for its type. It is the second half of the transactional outbox: the application commits its business change and the outbox row together, and this process delivers the row afterwards, in order, until the platform has taken it.

The concept page explains the contract (what gets written, the status codes, the positional batch API, idempotency). This page is about how the relay is built: the internal/outbox package.

The same outbox.Processor runs in two hosts:

Host Reads Authenticates with Leader-gated Admin API
fc-server with FC_OUTBOX_ENABLED=true The database fc-server is connected to (FC_OUTBOX_BACKEND=postgres, the default), MySQL 8.0+ or MariaDB 10.6+ (mysql, with FC_OUTBOX_MYSQL_URL), MongoDB (mongo, with FC_OUTBOX_MONGO_URI) or a SQLite file (sqlite, with FC_OUTBOX_SQLITE_PATH) A static bearer token, FC_OUTBOX_PLATFORM_AUTH_TOKEN Yes, with standby FC_OUTBOX_ADMIN_PORT on 127.0.0.1
fcdev outbox, run beside the application The application’s own PostgreSQL, or MySQL 8.0+ / MariaDB 10.6+ (FC_OUTBOX_SOURCE_DB_URL) client_credentials with the application’s service account (FC_OUTBOX_CLIENT_ID, FC_OUTBOX_CLIENT_SECRET, falling back to FLOWCATALYST_CLIENT_ID and FLOWCATALYST_CLIENT_SECRET), refreshed automatically and re-minted after a 401; or a static token Elects a leader through a lock in the source database, so any number may run (below) None

Both post to FC_OUTBOX_PLATFORM_URL. In fc-server the URL also accepts the legacy names FC_OUTBOX_API_URL, FC_API_BASE_URL and FLOWCATALYST_URL; without one the subsystem logs an error and does not start.

flowchart LR
  T[("outbox_messages")] -->|"ClaimPending<br/>status 0 to 9"| P["Processor.tick"]
  P -->|"grouped rows"| GD["GroupDistributor<br/>one serial lane per group"]
  P -->|"ungrouped rows, per type"| B["dispatchBatch<br/>one request per type"]
  GD --> D["HTTPDispatcher<br/>POST /api/.../batch"]
  B --> D
  D -->|"SUCCESS"| DEL["DELETE row"]
  D -->|"SKIPPED"| KEEP["keep row as a refusal<br/>(BAD_REQUEST)"]
  D -->|"retryable"| RQ["back to PENDING<br/>hold with backoff"]
  D -->|"BAD_REQUEST or FORBIDDEN"| BLK["keep row, [blocking] marker<br/>block the group"]
  D -->|"429"| H["hold for Retry-After<br/>release rows, no penalty"]

Each tick (every FC_OUTBOX_POLL_INTERVAL_MS, 1 second by default) the processor:

  1. Runs the start-up preparation once per leadership (below). Nothing is claimed until it has succeeded.
  2. Claims up to FC_OUTBOX_BATCH_SIZE (100) rows, leaving out everything that is currently held, paused or blocked (the ClaimFilter).
  3. Sorts the claim back into write order, (created_at, id). The claim is an UPDATE … RETURNING, which returns rows in no particular order, and rows written in one statement tie on created_at; the id breaks the tie because a TSID grows with time.
  4. Partitions the claim. A row whose group or type is held, or whose group is paused or blocked, is put straight back to PENDING with no penalty, and so is every later row of that group in the same claim. Grouped rows go to the distributor. Ungrouped rows are gathered by type and each type is sent as one batch request.

A second ticker runs crash recovery every 60 seconds: rows claimed (IN_PROGRESS, status 9) for more than 5 minutes belong to a relay that died, and go back to PENDING.

FC_OUTBOX_MAX_IN_FLIGHT (1,000) caps the rows in dispatch. A tick that finds the cap reached does nothing; the rows stay in the table for the next one.

On PostgreSQL the claim is one statement: a SELECT … FOR UPDATE SKIP LOCKED of status = 0 rows ordered by message_group, created_at, id, feeding an UPDATE that sets status = 9. Held and blocked groups, held types (for their ungrouped rows) and held single rows are excluded in the query. So is every group that still has a row in status 9 (IN_PROGRESS): the query reads those groups from one subselect over the status 9 partial index, so its cost follows the small in-progress set and not the backlog. Ungrouped rows are not affected. Without that, a blocked group with a backlog of a batch or more would fill every claim and starve the others.

On MongoDB there is no SKIP LOCKED: the claim is a find followed by an update. Two processors could claim the same document, which is one reason the subsystem is leader-gated.

GroupDistributor keeps an in-memory queue per message group and drains each group on its own goroutine, one row at a time, in claim order. At most FC_OUTBOX_MAX_CONCURRENT_GROUPS (10) groups drain at once; a group waiting for a slot simply queues. Ungrouped rows never pass through it.

When a row of a group does not succeed, the distributor stops draining that group and releases the group’s remaining claimed rows to PENDING (Release: no attempt counted, no error recorded). The next claim returns them, in order, behind the row that failed. Before sending each row the processor also re-checks the group: if an earlier row put a hold on it since the claim, the row is released rather than sent.

HTTPDispatcher.SendBatch is the only send path; a single grouped row is a batch of one. It posts {"items": [...]} to the endpoint for the row type:

Row type Endpoint
EVENT POST /api/events/batch
DISPATCH_JOB POST /api/dispatch-jobs/batch
AUDIT_LOG POST /api/audit-logs/batch
PUSH POST /api/push/batch (the push gateway)

A 2xx is not blanket success: the answer carries one result per item, matched to the rows by position. A result count that differs from the item count fails the whole batch as retryable rather than risk pairing an outcome with the wrong row. HTTP-level answers map as follows:

Answer Outcome for every row in the request
Transport error, timeout (30 s), 502, 503, 504 GATEWAY_ERROR, retryable
401 UNAUTHORIZED, retryable; a refreshing token source drops its cached token first
403 FORBIDDEN, a refusal
400 (exactly) BAD_REQUEST, a refusal
429 Not a failure: hold for Retry-After
Any other status (404, 409, 422, other 5xx) INTERNAL_ERROR, retryable

A per-item SKIPPED (an older platform answers it for an audit row it did not store) is also a refusal: the row is kept with status 2 and the message SKIPPED: the platform did not store this item, never deleted as delivered. Audit rows are ungrouped, so it blocks no group.

Only an exact 400 is treated as a refusal at the HTTP level, so a transient 404 from a misrouted proxy or a 409 cannot block a group for good.

DISPATCH_JOB payloads are normalised before sending: SDK releases before 2026-11-06 wrote metadata as an object, and the batch endpoint takes a list of {key, value}. The relay converts the object (keys sorted) so rows still waiting in an older application’s table deliver.

The processor never gives up on a row the platform could not take. Instead it holds what the row belongs to, in memory, keyed by:

Key Used for
group:<message group> A grouped row’s failure or 429 holds its whole group
type:<item type> A 429, or a batch where every row failed retryably (the request itself failed), holds the ungrouped rows of that type
item:<row id> A single ungrouped row that failed while the rest of its batch went through

A retryable failure records the attempt (retry_count, error_message), puts the row back to PENDING, and holds its key for a backoff that starts at 1 second and doubles with each consecutive failure of that key, up to 5 minutes, less up to a quarter of jitter. The hold is set before the row returns to PENDING, so no poll can claim it ahead of the hold. A failure that comes back while the key is already held (another batch of the same type was in flight) does not escalate it. The first success clears the count and logs the recovery.

A 429 holds the key for the Retry-After seconds (at least 1 s, at most 5 minutes, 5 s when absent or unreadable) and releases the rows without counting an attempt. A paused application or an application over its rate therefore waits in its own outbox, however long that lasts.

A refusal (BAD_REQUEST, FORBIDDEN) keeps the row in the table with its status code and its message prefixed [blocking] . With block-on-error (FC_OUTBOX_BLOCK_ON_ERROR, on by default) the row’s group becomes blocked: nothing behind it is sent until an operator acts. With block-on-error off, the refused row stays failed and its group carries on past it. Ungrouped rows never block anything.

stateDiagram-v2
  [*] --> RUNNING
  RUNNING --> PAUSED: pause
  PAUSED --> RUNNING: resume
  RUNNING --> BLOCKED: a row is refused
  PAUSED --> BLOCKED: a row is refused
  BLOCKED --> RUNNING: unblock, row re-queued
  BLOCKED --> RUNNING: skip, row marked skipped

GroupStateManager holds the non-default states. Paused is in memory only, so a restart resumes a paused group. Blocked is rebuilt from the table, so it survives restarts and failovers.

Before the first claim of every leadership, prepare makes the in-memory state match the table:

  1. RequeueRetryableFailures: rows an older relay left in a retryable failure status (after it used up a fixed number of attempts) go back to PENDING, keeping their history.
  2. MarkLegacyRefusals: refusals from relays that predate the markers get [skipped before upgrade] . Their groups had already moved on, so they block nothing; they stay in the table for inspection.
  3. BlockingFailures: for each group, its oldest refused row carrying [blocking] blocks the group again.

A processor that loses leadership forgets it was prepared, so a node that becomes leader later reloads the stored state rather than trusting its stale memory.

With FC_OUTBOX_ADMIN_PORT set, fc-server serves the state machine on 127.0.0.1:<port> only, with no authentication (it is not reachable from outside the host):

Route Effect
GET /outbox/groups Paused and blocked groups
GET /outbox/groups/blocked Blocked groups, with the blocking row id and error
GET /outbox/holds What is waiting out a backoff or a 429, until when, and after how many failures
POST /outbox/groups/{group}/pause and /resume Stop or restart a group (in memory)
POST /outbox/groups/{group}/unblock Re-queue the blocking row as a fresh attempt (retry_count reset) and let the group run again in order
POST /outbox/groups/{group}/skip Leave the blocking row failed, mark it [skipped by operator] , and let the group move past it

Unblock and skip answer 404 when the group is not blocked, and 500 (the group stays blocked) when the decision could not be stored. fcdev outbox has no admin API: there, fix or delete the refused row in the table and restart the relay, and the group is rebuilt from what is stored.

A PostgreSQL writer that inserts a PUSH row also sends NOTIFY fc_outbox_push in the same statement. The PostgreSQL repository listens on that channel on a connection of its own and wakes the processor at once, so a push is not delayed by the poll interval. It wakes once more after every reconnection, to catch anything missed, and the poll stays as the fallback.

In fc-server the processor polls only while it is the leader of the election on <FC_STANDBY_LOCK_KEY>:outbox. Without standby, run one copy. Two relays never claim the same PostgreSQL row (SKIP LOCKED), but a group’s order is kept inside one process, so a second relay would interleave a group’s rows. On MongoDB a second relay could also claim the same document. (fcdev outbox has its own election in the source database; see below.)

On failover the new leader prepares (rebuilding blocked groups from the table) and starts claiming. Rows the old leader had claimed and not finished stay IN_PROGRESS until crash recovery returns them after 5 minutes. Rows sent by the old leader whose answer was lost are sent again: events are deduplicated by their deduplicationId (the SDKs default it to the row id) and dispatch jobs by their idempotencyKey when they have one.

fcdev outbox is the relay you run beside an application whose outbox table is in the application’s own database. It is a separate small binary (the release workflow also builds an image, ghcr.io/flowcatalyst/fcdev; this documentation has not confirmed that it is published). Every setting is a flag with an environment variable, and the flag wins.

Leadership. By default (--leader, FC_OUTBOX_LEADER=true) the pollers of one outbox elect a leader through a lock in the source database, so you can run one per application task and any number may run. Only the leader claims and sends; the others stand by on one connection each. On PostgreSQL the lock is a transaction-scoped advisory lock held in an open transaction (it holds no snapshot and no table lock, so it blocks neither vacuum nor a migration, and it works through PgBouncer and RDS Proxy in transaction mode). On MySQL / MariaDB it is a named lock (GET_LOCK) on a connection of its own, so every poller must reach the same server, and the election does not work across the nodes of a Galera or Group Replication cluster. Outboxes in different schemas or databases elect separately. With --leader=false there is no election: use it only where something else guarantees one poller.

--leader-lease-ms (FC_OUTBOX_LEADER_LEASE_MS, default 5000, at least 100) sets how long a leader keeps sending after it last confirmed its lock. A standby takes over about 7 seconds after the leader’s process ends and about 17 seconds after the leader goes silent (a lost host, a partition, a paused process) at the default lease. A leader checks its leadership before every request, and a new leader waits 1.2 leases before it sends, so at most one sends. The rows the old leader had claimed stay IN_PROGRESS until the new leader returns them, about 35 seconds after it took over, and the claim passes over those rows’ message groups until then, so a group’s order holds across a takeover.

Health. The poller serves GET /health on --health-addr (FC_OUTBOX_HEALTH_ADDR, default 127.0.0.1:9180; off disables it): 200 when healthy, 503 when not, with a JSON report. fcdev outbox health asks it and exits 0 or 1, so it is the container health check and needs nothing but the binary: ["CMD", "/fcdev", "outbox", "health"]. A leader is unhealthy when its poll loop or its claims stall for --stall-timeout-ms (default 60000), or when it cannot get a platform token (--health-require-token, default true; set it false if the application’s tasks must not cycle during a platform outage, since the rows wait in the outbox either way). A leader whose poll loop stalls also gives up the leadership, and the command exits with status 1.

The schema. By default the poller creates outbox_messages if it is missing (--init-schema, FC_OUTBOX_INIT_SCHEMA=true). Set --init-schema=false whenever the application’s own migrations create the table: those use a plain CREATE TABLE, and a poller started beside the application can create the table first, so the application’s first migration then fails with “already exists”. With false the poller runs no DDL and waits for the table to appear.

Request size. --max-request-bytes (FC_OUTBOX_MAX_REQUEST_BYTES, default 8 MiB) caps the body of one request. The ungrouped rows of a type in a claim are sent in requests cut at the batch size or this many bytes, one after another; a grouped row is always sent alone. Keep it at or under half the platform’s FC_INGEST_BATCH_MAX_BYTES (16 MiB by default), and raise the platform’s cap first. If the platform answers 413 to a request of several rows, the relay splits it in two and sends the halves in order. A 413 on a single row is a refusal (PAYLOAD_TOO_LARGE): the row is kept and its group blocked, because the platform will never take it.

Variable Default Effect
FC_OUTBOX_ENABLED false Run the relay in fc-server
FC_OUTBOX_PLATFORM_URL none Where to post (required)
FC_OUTBOX_PLATFORM_AUTH_TOKEN none Static bearer token (fc-server)
FC_OUTBOX_BACKEND postgres postgres, mysql, mongo or sqlite
FC_OUTBOX_MYSQL_URL, FC_OUTBOX_SQLITE_PATH none MySQL / MariaDB or SQLite source (FC_OUTBOX_DB_URL is an alias of each)
FC_OUTBOX_MONGO_URI, FC_OUTBOX_MONGO_DB none, flowcatalyst MongoDB connection
FC_OUTBOX_BATCH_SIZE 100 Rows per claim
FC_OUTBOX_POLL_INTERVAL_MS 1000 Poll interval
FC_OUTBOX_MAX_IN_FLIGHT 1000 Rows in dispatch before a tick is skipped
FC_OUTBOX_MAX_CONCURRENT_GROUPS 10 Groups draining at once
FC_OUTBOX_BLOCK_ON_ERROR true A refused row blocks its group
FC_OUTBOX_ADMIN_PORT off The localhost admin API

Fixed in code: request timeout 30 s, backoff 1 s to 5 minutes, Retry-After bounds 1 s to 5 minutes, crash recovery every 60 s for rows claimed over 5 minutes ago. See the environment reference for aliases.

Situation What happens
The platform is down or unreachable Every send fails retryably; groups and types back off to one attempt every 5 minutes at most. Nothing is lost; delivery resumes on its own
The platform answers 429 The group or type waits Retry-After; no attempt is counted
The platform refuses a row The row stays with [blocking] ; its group stops until unblocked or skipped. Other groups carry on
The relay crashes mid-dispatch Claimed rows return to PENDING after 5 minutes; anything already accepted is deduplicated on resend
The token cannot be minted (fcdev outbox) Treated as GATEWAY_ERROR: retried with backoff
Start-up preparation fails (database error) Nothing is claimed; it is tried again on the next tick
The answer has the wrong number of results The whole batch is retried; no outcome is guessed
  • Never drop, never reorder. An outage used to exhaust a fixed retry count and strand rows. Now a retryable failure is retried for as long as it takes, and only a row the platform has positively refused stops its group. The failures are paced and visible principle applies: every hold and block is logged and shown by the admin API.
  • Blocks live in the table. The [blocking] marker makes the stored row the source of truth, so a restart or a failover can never let a group slip past its refused row.
  • One request per type for ungrouped rows. They carry no order, so they are batched for throughput; grouped rows are sent one at a time because order is their whole point.
  • Decisions: the transactional outbox, leader-gated processors.