Events and Transactional Outbox
Commands request actions; events record facts. Use domain events when they decouple meaningful modules, not for every function call.
How to apply it
Write the domain change and outbox row in one transaction. A worker publishes pending events; consumers deduplicate stable IDs. Version schemas, plan replay/retention, and keep payloads minimal.
Worked example
Project creation and a ProjectCreated outbox record commit together; if the broker is unavailable, a worker publishes later.
Common mistakes to avoid
Writing to database and broker as uncoordinated operations or assuming exactly-once delivery.
Practice task
Implement this concept in the capstone. Add one positive test, one negative or failure-path test, and a short note explaining the trade-off you chose.
- Commands request actions; events record facts. Use domain events when they decouple meaningful modules, not for every function call.
- Write the domain change and outbox row in one transaction.
What is the strongest production practice for Events and Transactional Outbox?