Transactional Outbox Pattern

An architecture where outgoing messages are persisted in local storage (the outbox) within the same transaction before being sent externally. This ensures safe, idempotent retries and eliminates dual-write inconsistencies during network failures.

General Meaning

The Transactional Outbox pattern is a reliable messaging design that synchronizes database updates with external message dispatching without requiring distributed two-phase transactions. In distributed systems, attempting to update a database and send a network message in an uncontrolled sequence frequently leads to partial failures where one succeeds while the other fails.

Instead of publishing directly to external message brokers or peer nodes, an application stores the outbound payload directly into a local outbox table inside its local transactional boundary. A background dispatcher or sender process then reads uncommitted records from the outbox table and delivers them externally. If network transmission fails, the sender safely replays the exact same stored record.

Why It Matters

  • Eliminating the dual-write problem: Avoids race conditions where a database commit succeeds but message publishing fails, or vice versa.
  • Preserving payload immutability and repeatability: Storing the finalized byte sequence before transmission guarantees that retry attempts cannot accidentally mutate parameters or content.
  • Enhancing fault tolerance: Outbox tables act as durable local buffers during broker or network outages, resuming transmission automatically once connectivity is restored.

How the Site Factory Uses It

In the Site Factory, autonomous agent coordination across Studio machines (A2A: Agent-to-Agent) uses an EvidenceOutbox implemented on a host-local SQLite database before transmitting hardware benchmark metrics or inference evidence. Rather than firing raw HTTP requests directly, the evidence payload is committed locally with PRAGMA synchronous=FULL and file permission 0600 under honbu/a2a_evidence.py.

The SQLite evidence table uses PRIMARY KEY(job, generation, kind). When network transmission fails and requires retrying via publish_saved, the codebase strictly forbids re-running models or re-measuring benchmarks; it enforces sending only the identical persisted byte payload from the local outbox. Authoritative execution leases and quota approvals remain managed separately in D1 rather than within the local outbox.

Caveats & Operational Rules

  • Never regenerate results during retries: Re-running inference or benchmarks changes timestamps and measurements, conflicting with previously attempted writes; always replay identical outbox records.
  • Outbox is not a substitute for central state: The local outbox acts purely as a pre-send safety buffer, not as an authoritative ledger for cluster-wide job allocation, which belongs in Cloudflare D1.
  • Purge lifecycle is required: Stored outbox records must be cleaned up or archived systematically once confirmed, preventing unbounded local disk growth.

Related Terms

References

  • Book: Martin Kleppmann, *Designing Data-Intensive Applications*, Chapter 11 (Stream Processing: Transactions and the Outbox Pattern)

Verified: 2026-11-08