Tech challenge · Data Architecture

Orders in the database but missing from the event stream

MediumData Architecture

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.

Learn more

More Data Architecture challenges

Today's challenge and the full archive