Engineering Decisions · Senior · Question 4 of 14
After saving an order, the service must publish an event to a broker. Events must not be lost, and the broker can't join a database transaction. What do you do?
- 1Commit first, then publish with retries in the handler
- 2Publish first, then commit once the broker confirms
- 3A transactional outbox, published by a relay
Show the answer
Correct answer: A transactional outbox, published by a relay
Explanation
Writing the event in the same transaction as the order means both exist or neither does, and a relay delivers it later. Publishing after commit fits events you can afford to lose, but a crash between the two steps drops the event. Publishing first fits nothing that must stay consistent, because a failed commit leaves consumers reacting to an order that doesn't exist.