SOLID & Design Patterns Interview Question #87
What is the Outbox Pattern?
DDD Boundaries, Resilience, Caching & Practical ASP.NET Core Design Mid-Level Intermediate
Quick Interview Answer
The Outbox Pattern helps make database changes and messages reliable without requiring one distributed transaction. The application stores the business change and an outgoing message record in the same local database transaction.
Detailed Explanation
The Outbox Pattern helps make database changes and messages reliable without requiring one distributed transaction. The application stores the business change and an outgoing message record in the same local database transaction.
A background process later publishes the outbox messages and marks them as processed. Consumers and publishers still need appropriate idempotency because delivery can occur more than once.
Code Example
await using var tx =
await db.Database.BeginTransactionAsync();
db.Orders.Add(order);
db.OutboxMessages.Add(
OutboxMessage.From(orderConfirmed));
await db.SaveChangesAsync();
await tx.CommitAsync();
// A worker publishes the outbox later.