Module 3: Event-Driven Architecture: Worked Examples
Example 1: Publish Without a Dual Write
Problem. An order transaction commits, but publishing OrderAccepted fails.
Wrong attempt. Retry publishing from application memory. A process crash loses the event; publishing first can emit an event for a rolled-back order.
Correct reasoning. Write the order and outbox row in one local transaction. A relay publishes with retries; consumers deduplicate by event identity. Monitor outbox age and relay failures.
Example 2: Design an Event as a Fact
UpdateCustomer is a command and leaks intent. CustomerAddressChanged is an immutable past-tense fact with event ID, aggregate ID, schema version, occurred time, producer, and the minimal stable business data consumers need. Avoid copying the producer’s whole database row.