Skip to content
Back to projects

outbox-kit

In Development

Change the database and tell another system, without one happening and the other not

Role: Solo developer

Solo · Since Nov 2026 · Public repo

.NET 10EF CorePostgreSQLxUnitTestcontainers
25
Tests, against real PostgreSQL
0
Crash test: messages lost

A small .NET library for the transactional outbox on EF Core and PostgreSQL, plus an idempotent consumer. About 300 lines, with tests that prove its guarantees against a real database, including one that kills the process mid-dispatch.

Problem

Saving a change and then publishing a message are two steps. If the process dies between them, the change exists and nobody was told. Swap them and a message goes out for a change that never committed.

Solution

The message is a row written in the same SaveChanges as the change, so both commit or neither does. A dispatcher locks a batch with FOR UPDATE SKIP LOCKED, publishes and marks rows in one transaction. The consumer records the message id and runs its handler in one transaction, so a redelivery is skipped.

Not done yet

PostgreSQL only. No ordering guarantee once a message fails, no cleanup of processed rows and no metrics. I did not benchmark it, so I make no throughput claim. It is not published to NuGet.

Architecture highlights

  • The chaos test runs a second process and ends it with Environment.FailFast between publish and commit. Nothing is marked processed, a second worker finishes: all 20 messages are processed and the broker saw 23 publishes, three of them duplicates
  • A consumer that replays every one of those publishes twice applies each effect exactly once. At-least-once from the outbox plus the inbox gives one effect per message
  • Three dispatchers at once publish each of 40 messages exactly once, and a poison message is retried then parked without blocking the rest
  • I publish inside the locking transaction on purpose: a crash before the commit rolls back every mark made in that run, at the cost of a long transaction when the broker is slow. There is no ordering guarantee at all
  • An independent audit found a real bug in my first version: a publisher timeout was never counted as an attempt, so a message could be republished forever and never parked. Fixed, with the dispatcher no longer touching the caller's change tracker, and 16 more tests