What It Does
Guarantees that events are published to NATS, even if NATS is temporarily down.How It Works
- Save data + event to PostgreSQL in same transaction
- Background worker (relay) publishes events from outbox to NATS
- Automatic retry on failure
- Events are marked as published once successful
Key Files
| File | Purpose |
|---|---|
internal/shared/infrastructure/outbox/event.go | Outbox event model |
internal/shared/infrastructure/outbox/repository.go | Repository interface |
internal/shared/infrastructure/outbox/postgresql/outbox_repository.go | Postgres implementation |
internal/shared/infrastructure/outbox/relay.go | Background worker |
Usage Example
Monitoring
Configuration
- Poll interval: 1 second
- Max retries: 3 attempts
- Cleanup: Deletes published events older than 7 days (configurable)