Transactional Outbox & Deduplicating Inbox in Distributed Services

Guaranteeing atomic state persistence and idempotent event delivery across asynchronous message brokers with EricksonLopez.Outbox.

In distributed architectures, performing dual writes between a relational database and an external message broker (RabbitMQ, Kafka, Azure Service Bus, AWS SQS) leads to silent inconsistency during network partitions or process crashes.

The Dual-Write Problem

Consider a service handler that commits database state and then publishes an event over the network:

await _database.SaveChangesAsync(ct);
await _bus.PublishAsync(new OrderPlacedEvent(order.Id), ct);

If the database transaction commits and the process crashes or the broker connection drops before PublishAsync succeeds, downstream consumers never learn that the order was placed. Rolling back the already-committed transaction is impossible.

The Architecture of EricksonLopez.Outbox

The dotnet-outbox family (36 published NuGet packages including EricksonLopez.Outbox and EricksonLopez.Inbox, plus 2 local unpublished packages EricksonLopez.Inbox.PostgreSql and EricksonLopez.Outbox.OpenTelemetry in local v4.2.0) solves dual-write divergence in three stages:

  1. Atomic Outbox Persistence: The serialized domain event is written to the outbox_messages table inside the exact same ACID transaction that persists domain state.
  2. Batched Polling & Dispatch: A background relay worker reads pending rows in batches (using PostgreSQL UNNEST array updates in PostgreSqlOutboxRepository to mark processed batches atomically) and dispatches them to the configured broker adapter.
  3. Consumer Inbox Deduplication: Downstream handlers record each processed message_id inside inbox_messages (EricksonLopez.Inbox / EricksonLopez.Inbox.Abstractions) so at-least-once broker redeliveries execute business effects at most once.

This dual-layer invariant guarantees that business state and asynchronous event publication remain coupled—satisfying Principle 1 (Correctness over convenience).

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.