outbox

Persist domain events and outbox messages atomically in .NET microservices.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill outbox-faysilalshareef
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: outbox
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/microservice/command/outbox
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill outbox-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents lost or inconsistent domain events by ensuring events and outbox messages are persisted atomically and published reliably to a message broker, eliminating race conditions between database commits and external publishing.

Core Features & Use Cases

  • Atomic persistence: Save domain events and OutboxMessage records together via IUnitOfWork and a single SaveChangesAsync call.
  • FK-based outbox: OutboxMessage wraps an Event via a navigation property (shared primary key) rather than serializing event bodies.
  • Reliable publisher: Singleton ServiceBusPublisher uses Task.Run, a lock and a lockedScopes counter, creates a DI scope for DB access, reads in batches of 200, publishes each message, removes it, and saves to guarantee at-least-once delivery.
  • Use Cases: Order management events, cross-service integration, audit/event sourcing scenarios in .NET microservices using Azure Service Bus.

Quick Start

Use the outbox skill to implement a CommitEventService that saves events and matching OutboxMessage entities in one SaveChangesAsync call and then triggers the singleton ServiceBusPublisher to publish them.

Frequently Asked Questions about outbox

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reliably publish domain events in .NET without losing messages during database commits?▼

To prevent lost domain events, the outbox pattern persists events and OutboxMessage records atomically via a single SaveChangesAsync call using IUnitOfWork, eliminating race conditions between database commits and external message broker publishing.

What is the outbox pattern and when do I need it for EF Core microservices?▼

The outbox pattern saves domain events and OutboxMessage records together in one database transaction. You need it in EF Core microservices when cross-service integration via Azure Service Bus requires guaranteed event persistence without race conditions between commits and publishing.

How do I implement an outbox pattern background publisher with Azure Service Bus and EF Core?▼

Implement a singleton ServiceBusPublisher using Task.Run and lock-based concurrency that creates a DI scope for database access, reads OutboxMessage records in batches of 200, publishes each message, deletes it, and saves changes to guarantee at-least-once delivery.

Does the outbox pattern support idempotency for event publishing in .NET?▼

The outbox pattern supports idempotency by using FK-based OutboxMessage wrapping of Event via a shared primary key navigation property rather than serializing event bodies, combined with batched reads of 200 and at-least-once delivery semantics to prevent duplicate processing.

Why does my domain event publishing fail when the database commits but the message broker is unavailable?▼

Event publishing fails because database commits and external broker publishing are not atomic. The outbox pattern solves this by persisting domain events and OutboxMessage records together via IUnitOfWork and a single SaveChangesAsync call, then using a background publisher to dispatch them reliably.

Can I use a shared primary key for OutboxMessage instead of serializing event bodies in EF Core?▼

Yes, the outbox pattern uses FK-based OutboxMessage wrapping of Event via a navigation property with a shared primary key rather than serializing event bodies, maintaining referential integrity within EF Core while enabling atomic persistence through IUnitOfWork and SaveChangesAsync.