Distributed systems · .NET

Publish a domain event through an outbox and handle duplicates

Follow a state change through Kafka or Azure Service Bus.

When an aggregate confirms a booking, the application may need to notify another context. If the database commits and publishing fails, that other context may never learn about the change.

An outbox records the state change and the message to publish in the same database transaction. A worker reads pending messages, publishes them and marks the records as processed.

A worker that stops after publishing but before marking the record can publish the same message again. The consumer can use a stable identifier to detect replay and record processing in the same transaction as its business effect when they share a store.

Test the crash after publishing, replay of the same message and worker recovery. If the effect calls an external provider, check what the provider’s idempotency key actually guarantees.

All articles

Portfolio assistant