The Dual Write Problem
Naive approach: save entity to DB, then publish event to message broker.
1. UPDATE orders SET status = 'shipped'
2. publish("order-shipped", event)
What if step 2 fails? Order is marked shipped in DB but no event was published. State inconsistency.
What if we reverse? Event published but DB write fails → event about a change that didn't happen.
No distributed transaction between DB and message broker (without 2PC/XA, which is expensive and complex).