Orders in the database but missing from the event stream
An order service saves each order to its database and then publishes an OrderCreated event to Kafka. A few orders a day never appear downstream. What is the design flaw, and what patterns fix it?
Think it through or sketch an answer first, then open the hint or the solution.
Show a hint
What happens if the service crashes between the two writes?
Show the solution
This is the dual-write problem: two systems cannot be updated atomically, so a crash or a failed publish after the database commit loses the event. Use the transactional outbox: write the order and an outbox row in the same database transaction, and have a relay (often change data capture on the outbox table) publish it. Alternatively, use CDC on the orders table itself.
Common mistakes
- Publishing the event first, which creates events for orders that were never saved.
- Adding retries in the service: they do not help when the process itself dies.
How did you do? Your answer is saved in this browser and comes back for revision later.
Learn more
- Change Data Capture & the Outbox PatternData Architecture Patterns
- Data Integration PatternsEnterprise Data Architect