Production engineering
Reveal answer and reasoning
An outbox addresses a local atomicity problem before it addresses delivery. The business row and its publication intent need one storage transaction, otherwise a failure between two commits can leave an order without an event or an event for a rejected order. This lesson executes both writes in SQLite and injects a failure before commit. It does not merely draw a domain-event relationship.
The portable immutable bundle keeps related facts together in memory, while only the actual database experiment can establish persisted rollback. No broker, subscriber or external side effect is hidden behind creation of the outbox row.
Publishing before commit creates a different failure window from publishing afterward, and neither order alone creates a distributed atomic transaction. A worker can fail after a broker accepted an event but before its local sent marker is stored. Treating an outbox insert or an HTTP201 as proof of delivery would therefore overstate the result. Likewise, catching a database exception and continuing with an independently published event can break the intended invariant.
The controlled503 in this lesson is deliberately before commit; a post-commit lost response is a distinct scenario explored later rather than silently described as the same rollback. The outbox payload here is only a short quantity description, and event creation performs no network call, so a sent-message claim would lack any supporting observation.
What a strong answer covers
- The portable record groups quantity2 with event order:2; it does not execute SQL.
- Actual pre-commit failure leaves orders0/outbox0; valid commit leaves1/1.
- Persisted publication intent and external delivery have separate failure boundaries.
Common pitfall
Equating a committed outbox row with broker acceptance or exactly-once consumer execution.
Follow-up questions
- What state appears if business and event rows use separate commits?
- How does a lost acknowledgment after remote delivery affect replay?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.