The outbox pattern commits business data and an event-to-publish row in the same database transaction. A separate publisher later sends the row to a broker, surviving a crash after commit.
The demo commits Order and Outbox together before publishing. Publishing may be retried, so consumers should handle duplicates.
When to use
Use it when a database write and message publish must not split into one-sided success.