Search by

phil / outbox

phil

Never lose an event after a database write: the event is saved in the same transaction as the data, then delivered to its listeners, with retries until they accept it.

0.2.0-alpha 2026-11-24 22:00 UTC

This package is auto-updated.

Last update: 2026-11-25 13:24:33 UTC


README

OpenSSF Scorecard

Never lose an event after a database write: the event is saved in the same transaction as the data, then delivered to its listeners, with retries until they accept it.

A library that writes its state and then dispatches an event loses the event when the listener, the dispatcher or the process fails between the two: nothing tells the listeners again. With phil/outbox, the library records the event in the same transaction as its write, and a relay tells the listeners afterwards, until they accept it.

phil/outbox is a plain PHP library on the PSR-14 and PSR-20 interfaces, without a dependency on Symfony Messenger. phil/outbox-bundle keeps the records in a table of the application's Doctrine DBAL connection and runs the relay in Symfony.

Status

Part State
Outbox::record() on a store, the allowlist of the codecs, the bounded payload of identifiers Implemented and tested
The relay: leases, order per key, backoff, dead records, skipped records, the grace of unknown types, at-least-once delivery Implemented and tested
The housekeeping: dead records inspected, tried again or discarded, retention of the delivered records Implemented and tested
The store in memory, and the contract tests every store passes Implemented and tested
The fuzz target of the payload reader, the benchmark of a relay batch Implemented

Documentation

Document What it covers
Installation Requirements and installing.
Recording Outbox::record(): event types, payloads, ordering and idempotency keys, the transaction.
Codecs How a record becomes an event again, and the generic RecordedEvent.
Relaying The relay: leases, order per key, retries, dead records, and why listeners are idempotent.
Housekeeping The dead records, the retention of the delivered records, the counts.
Stores The store contract, the store in memory, and the contract tests of an adapter.
Adoption guide Moving a library that records then dispatches to the outbox, with a worked example, and keeping it out of the way of an erasure.
Extension points What an application may replace or add, and when it is stable.
Testing The package's tests, its fuzz target and its benchmark.
Reference Every public type, with its role.

Quick start

composer require phil/outbox
use Phil\Outbox\Codecs;
use Phil\Outbox\Memory\InMemoryOutboxStore;
use Phil\Outbox\RecordedEventCodec;
use Phil\Outbox\Relay;
use Phil\Outbox\StoreOutbox;

$store = new InMemoryOutboxStore();
$codecs = new Codecs([new RecordedEventCodec(['quiz.completed'])]);
$outbox = new StoreOutbox($store, $codecs);

// In the transaction of the write it describes:
$outbox->record('quiz.completed', ['quiz' => 'q-42', 'member' => 7], orderingKey: 'quiz:q-42');

// Later, in a worker:
$report = new Relay($store, $codecs, $dispatcher)->relay();

Requirements

PHP 8.5 or later, with the mbstring and sodium extensions.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.