What It Does

Guarantees that events are published to NATS, even if NATS is temporarily down. The outbox carries domain events only (for example rental.listing.approved, error_report.created). Row-level history in audit_trails is written by Postgres AFTER triggers in the same transaction (ADR-0002), not by outbox events.

How It Works

  1. Save data + event to PostgreSQL in same transaction
  2. Background worker (relay) publishes events from outbox to NATS
  3. Automatic retry on failure
  4. Events are marked as published once successful

Key Files

Usage Example

Monitoring

Configuration

  • Poll interval: 1 second
  • Max retries: 3 attempts
  • Cleanup: Deletes published events older than 7 days (configurable)

Testing