You save an order to the database and then publish an order.created event. Two lines of code. What could go wrong?
DB :: transaction ( function () use ( $order ) { $order -> save (); });
Kafka :: publish ( 'order.created' , $order ); // what if this fails?
Enter fullscreen mode
Exit fullscreen mode
This is a dual write : one operation writing to two different systems (database + broker, database + cache, database + search index) with no transaction covering both.
Why it breaks:
Partial failure: the order is committed, but the publish fails (network blip, broker down, process killed mid-request). The order exists, and no downstream service ever hears about it.
Swapping the order doesn't help: publish first and you can end up with an event for an order that was never saved.
Race conditions: two concurrent requests can write in a different order to each system, leaving them out of sync.
It even hides in familiar patterns.…