Outbox
The outbox is how a Laravel application publishes to FlowCatalyst. You write a row into an
outbox_messages table in your own database, in the same transaction as the business change. A
separate relay (the platform’s outbox processor, or fcdev outbox locally) reads the rows and sends
them on. The reasoning, the row types and the relay’s behaviour are in
The transactional outbox; this page covers the PHP side.
Publish and run the migration, then point the SDK at the credentials and client it should write for.
php artisan vendor:publish --tag=flowcatalyst-migrationsphp artisan migrateThe migration creates outbox_messages with the columns the relay reads (id, type,
message_group, payload, status, retry_count, created_at, updated_at, error_message) and
three SDK columns (client_id, payload_size, headers), plus the indexes the relay’s polling
queries use. New rows are written with status 0 (pending); the relay owns every later transition.
Rows are stamped in UTC with millisecond precision (2026-12-01 10:15:02.481) whatever PHP’s default
time zone; before 0.27.0 they were in PHP’s local time to the second. The migration now creates
created_at and updated_at as DATETIME(3) (MySQL) or TIMESTAMPTZ(3) (PostgreSQL); a table made
by an earlier version keeps its columns, so alter them if you
want the precision.
| Config key | Env var | Default | Meaning |
|---|---|---|---|
flowcatalyst.outbox.driver |
FLOWCATALYST_OUTBOX_DRIVER |
database |
database (MySQL or PostgreSQL) or mongodb. Any other value falls back to database. |
flowcatalyst.outbox.connection |
FLOWCATALYST_OUTBOX_CONNECTION |
null (default connection) |
Laravel database connection holding the table. |
flowcatalyst.outbox.table |
FLOWCATALYST_OUTBOX_TABLE |
outbox_messages |
Table or collection name. |
flowcatalyst.outbox.strict_transactions |
FLOWCATALYST_OUTBOX_STRICT_TRANSACTIONS |
false |
Refuse writes made outside a transaction. See below. |
flowcatalyst.outbox.warn_outside_transaction |
FLOWCATALYST_OUTBOX_WARN_OUTSIDE_TRANSACTION |
true |
Log a warning for a database-driver write outside DB::transaction(...). Set false to silence it; strict_transactions still wins. |
flowcatalyst.outbox.client_id |
FLOWCATALYST_OUTBOX_CLIENT_ID |
the service-account client_id |
Value of the row’s client_id column. |
flowcatalyst.outbox.client_code |
FLOWCATALYST_CLIENT_CODE |
null |
Default client (by code) of a push that names none. |
flowcatalyst.outbox.audit_enabled |
FLOWCATALYST_OUTBOX_AUDIT_ENABLED |
false |
Whether the default unit of work also writes audit-log rows. |
The relay must also be configured and running; see Outbox processor.
flowcatalyst.outbox.enabled, tenant_id and default_partition exist in the published config but
the SDK does not read them.
If no client_id resolves, every create* call throws OutboxException (“Client ID is required”).
Fully qualified codes
Section titled “Fully qualified codes”An event type and a dispatch-job code must be four non-empty, colon-separated segments:
application:subdomain:aggregate:action, for example shop:orders:order:created. A bare code makes
the DTO constructor throw InvalidArgumentException.
Events
Section titled “Events”use FlowCatalyst\Facades\Outbox;use FlowCatalyst\Outbox\DTOs\CreateEventDto;use Illuminate\Support\Facades\DB;
DB::transaction(function () use ($order) { $order->save();
$eventId = Outbox::createEvent( CreateEventDto::create( type: 'shop:orders:order:created', data: ['orderId' => $order->id, 'total' => 99.99], )->withCorrelationId('corr-abc-123') ->withSource('order-service') ->withMessageGroup('orders') // per-group FIFO ordering );});createEvent returns the outbox row id (a TSID). createEvents(array $events) writes a batch in
one insert and returns the ids in order.
The builder methods on CreateEventDto are withCorrelationId, withCausationId,
withDeduplicationId, withSource, withSubject, withMessageGroup, withClientCode,
withHeaders and withContextData. Each returns a new instance. If you set no deduplication id, the
row id is used, so a batch the relay sends twice after a lost response does not create two events.
withHeaders values go in the row’s headers column; the rest go in the payload. data may be an
array or a JSON string, which is sent as it is (a string that is not valid JSON throws
InvalidArgumentException). withTime sets the event’s time (RFC 3339 UTC with milliseconds);
without it the platform stamps the time when it accepts the event.
withMessageGroup sets the row’s message_group. Rows of one group reach the platform in order; see
Ordering. withClientCode names the FlowCatalyst client the event belongs to.
Dispatch jobs
Section titled “Dispatch jobs”A dispatch job is a direct webhook delivery with no subscription matching.
use FlowCatalyst\Facades\FlowCatalyst;use FlowCatalyst\Outbox\DTOs\CreateDispatchJobDto;
$job = CreateDispatchJobDto::create( source: 'order-service', code: 'shop:orders:warehouse:notify', targetUrl: 'https://warehouse.example.com/webhook', payload: ['orderId' => 'ORD-123', 'action' => 'prepare'], dispatchPoolId: $warehousePoolId, )->withCorrelationId('corr-abc-123') ->withClientCode('acme') ->withConnectionId($connectionId) ->withIdempotencyKey('warehouse-ORD-123') ->withMetadata(['orderId' => 'ORD-123']);
$outboxId = Outbox::createDispatchJob($job); // through the outbox: returns the row id$jobId = FlowCatalyst::dispatchJobs()->create($job); // straight to the platform: returns the job idBoth paths send the same item (CreateDispatchJobDto::toBatchItem()). createDispatchJobs(array)
writes several rows. Direct calls use POST /api/dispatch-jobs/batch, need the
platform:messaging:batch:dispatch-jobs-write permission, and are all-or-nothing: a refused item
fails the request with FlowCatalystException and creates nothing. dispatchJobs()->batch([...])
returns one DispatchJobResult (id, status, error) per job.
withConnectionIddelivers through that connection. Pausing the connection holds the job, and for a job with no subscription the connection’s service account signs the delivery.withIdempotencyKey(at most 100 characters) makes the create idempotent within the application and client: a repeat creates nothing and answers the first job’s id. Set one on direct calls: a batch whose every job has a key is repeatable, so the client sends it again after a 502 to 504 or a failure after sending. Without keys a lost answer ends inOutcomeUnknownExceptionand the batch is not sent again (see Control plane).withClientCodeorwithClientIdsets the job’s client (an id wins over a code).withMetadatatakes an associative array (sent key-sorted as[{key, value}]) or a list of{key, value}pairs.withScheduledForandwithExpiresAt(the olderscheduledFor()andexpiresAt()are aliases) take aDateTimeInterfaceand send it as RFC 3339 UTC with milliseconds (2026-12-01T10:15:02.481Z). The platform does not claim the job beforescheduledFor, and settles itEXPIREDif delivery comes afterexpiresAt. AnexpiresAtat or beforescheduledForthrowsInvalidArgumentException. Before 0.27.0 these two were accepted but dropped, so code that set them now schedules or expires the job. They need a platform that takes them.withKind('EVENT'|'TASK'),withDispatchPoolCodeandwithConnectionCodeare each sent only when set. An explicitdispatchPoolIdorconnectionIdwins over the code. They need a platform that takes them.withHeadersand the retry-strategy argument are accepted but not sent: the platform does not take them.
For what a dispatch job is, see Dispatch jobs.
Audit logs
Section titled “Audit logs”use FlowCatalyst\Outbox\DTOs\CreateAuditLogDto;
Outbox::createAuditLog( CreateAuditLogDto::create(entityType: 'Order', entityId: $order->id, operation: 'ship') ->withOperationData(['carrier' => 'DHL']) ->withPrincipalId($principalId) ->withApplicationCode('shop') ->withClientCode('acme'));Other builders: withPerformedAt, withSource, withCorrelationId, withMetadata, withHeaders.
createAuditLogs(array) writes a batch.
Pushes
Section titled “Pushes”A push tells the people looking at a screen that something changed. See Push for the model. Write it in the same transaction as the change:
use FlowCatalyst\Outbox\DTOs\CreatePushDto;
DB::transaction(function () use ($order) { $order->save(); Outbox::createPush( CreatePushDto::create("shop:orders:{$order->id}", 'order.updated', ['status' => 'shipped']), );});createPushes(array) writes several. Builders: withId (at most 26 characters, becomes the
pushId), withClientCode, withMessageGroup, withUngrouped, withMaxDataBytes.
topicis{application}:{segment}(:{segment})*.typematches[a-z][a-z0-9-]*(.[a-z][a-z0-9-]*)*;reset,auth-expired,subscribedandfw.*are reserved.datais a JSON object, 16 KiB by default and up to 64 KiB withwithMaxDataBytes.- The row’s message group is the topic, so pushes of one topic stay in order.
withUngrouped()opts out for signal-only topics. - A push the platform would refuse is refused on build:
createPushthrowsPushException, whoseerrorCode()is one ofTOPIC_INVALID,TYPE_INVALID,TYPE_RESERVED,DATA_INVALID,DATA_NOT_OBJECT,DATA_TOO_LARGE,PUSH_ID_INVALID,CLIENT_INVALID. - On PostgreSQL the insert also runs
pg_notify('fc_outbox_push', '')in the same statement, so the relay wakes when your transaction commits. MySQL and MongoDB cannot notify; the relay’s poll delivers the row. - The relay must know the
PUSHtype. A processor that predates push posts it as an unknown type and fails the row.
Rules, keys and tickets for who may listen are covered with the push sync in Control plane.
In a use case
Section titled “In a use case”When you use the SDK’s use-case envelope, add pushes to the plan so they are written after the event in the plan’s transaction:
return Plan::save($order, $repo, $event)->andPush( CreatePushDto::create("shop:orders:{$order->id()}", 'order.updated', ['status' => 'placed']),);An invalid push fails the plan with a validation error and the transaction rolls back. The unit of
work must implement PushesUnitOfWork; OutboxUnitOfWork, the default binding of UnitOfWork,
does.
Transactions
Section titled “Transactions”An outbox write is atomic with your business write only if both happen in one transaction on one
connection. DatabaseDriver uses DB::connection($name), so it joins whatever transaction is open.
strict_transactions |
Write outside DB::transaction |
|---|---|
false (default) |
Logs a warning and writes anyway (unless warn_outside_transaction is false, which silences the warning only). The business change and the event can then disagree. |
true |
Throws OutboxException (“Outbox write attempted without an active database transaction”). |
Turn it on in new code. The check applies to the database driver only; MongoDriver has none.
To write to a connection other than the configured one, build a driver and pass it per call:
use FlowCatalyst\Outbox\OutboxManager;
$driver = OutboxManager::driverForConnection('tenant_db');Outbox::createEvent($event, $driver);Errors
Section titled “Errors”| Exception | Cause |
|---|---|
InvalidArgumentException |
A bare event type or dispatch-job code. |
OutboxException |
No client id; insert failed (driver message included); not in a transaction under strict mode; mongodb driver without mongodb/laravel-mongodb. |
PushException |
An invalid push (see codes above). |
All SDK exceptions extend FlowCatalystException. Database requirements and the MongoDB collection
are on Database; testing writes is on Testing.