Distributed Saga & Outbox

Maintain 100% data consistency across federated database silos, even during network failures, using the Transactional Outbox pattern.

01 Atomic Persistence

When a mutation occurs (Create/Update/Delete), the primary silo transaction atomatically persists both the entity and a "Pending Task" in the distributed_outbox table.

NATS Streaming (CQRS)

Subject Pattern: go.duck.events.{entity}.{action}

High-performance internal messaging bridge. Supports wildcard subscriptions (e.g., go.duck.events.article.*) for ultra-fast, decoupled service-to-service orchestration.

NATS Performance & CQRS

NATS acts as the nervous system for your microservice. While MQTT is optimized for UI/WebSockets, NATS provides the dot-separated power needed for enterprise message routing.

Subject Strategy Dot-separated subjects for hierarchical routing and filtering.
CQRS Evolution Easily separate Reads and Writes by listening to NATS events for cache invalidation.

How it Works

# The Saga Workflow
1. Client sends POST /cars (Federated Entity)
2. Controller opens transaction on Master Silo
3. Local Car record is saved
4. "PROPAGATE_CREATE" task is saved to `distributed_outbox`
5. Transaction COMMIT
6. OutboxWorker picks up the task
7. OutboxWorker broadcasts to Silo B, C, D...
8. On Success, task is marked "COMPLETED"
            

Outbox Schema

Every silo in your infrastructure includes this safety net automatically:

Field Type Description
event_typeStringCREATE, UPDATE, DELETE, BULK_...
payloadJSONBThe delta or entity data
statusStringPENDING, COMPLETED, FAILED
retry_countIntExponential backoff tracking