Skip to content
your terminal
zsh — orders
Orders.Api
ASP.NET Core · PostgreSQL
one transaction
orders
outbox_messages
OutboxPublisher
background service · every 1 s
RabbitMQ
exchangeorders
queueshipping.order-placed
Shipping.Worker
its own database
inbox_messages
shipments0
Place an order

Publish events reliably with the outbox and inbox patterns in .NET 10 ​

Ten small steps take you from an empty folder to an orders API and a shipping worker that never lose an event and never process one twice, built by hand with EF Core, PostgreSQL and RabbitMQ. Each step is a git commit you can read, run and compare.

Part 1: Build the outbox and inbox

Save orders and their events in one transaction, publish them to RabbitMQ and consume them exactly once in effect.

  1. 01Create the projectCreate the solution and an Orders API, and start PostgreSQL and RabbitMQ with Docker Compose.
  2. 02Save orders with EF CoreAdd EF Core with Npgsql, create the orders table with a migration and expose endpoints to place and read orders.
  3. 03Write events to the outboxSave an OrderPlaced outbox message in the same transaction as the order to solve the dual-write problem.
  4. 04Publish the outbox to RabbitMQWrite a background service that reads pending outbox rows and publishes them to RabbitMQ with publisher confirms.
  5. 05Consume events in a workerCreate a shipping worker service that consumes OrderPlaced messages with manual acknowledgements.
  6. 06Make the consumer idempotent with an inboxRecord each message id in an inbox table in the same transaction as the shipment so duplicates are skipped.

Part 2: Make it production-ready

Add retries and dead-lettering, safe concurrent publishers, end-to-end tracing, health checks and cleanup.

  1. 07Retry failures and dead-letter poison messagesRetry failed publishes with exponential backoff and send messages the worker cannot process to a dead-letter queue.
  2. 08Run several publishers safelyClaim outbox batches with FOR UPDATE SKIP LOCKED so several API instances publish without duplicates.
  3. 09Trace a request across the outboxStore the trace context in the outbox, send it as a message header and view one trace from API to worker in the Aspire dashboard.
  4. 10Add health checks and outbox cleanupAdd liveness and readiness checks, report outbox lag and delete processed outbox rows after a retention period.

MIT licensed. Every step is a commit: git checkout step-01.