Cards/KafkaSystem Design · Day 11Aug 11, 2026

The Two Writes That Must Be One

The Two Writes That Must Be One — system design card, day 11, kafka

Your service saves an order to Postgres, then publishes "OrderCreated" to Kafka.

Between those two lines, the process dies.

The order exists. Nobody downstream knows. No warehouse, no email, no invoice. And no error was ever thrown — the transaction committed cleanly.

Flip the order and it's worse: the event fires, the database write fails, and the whole system now reacts to an order that doesn't exist.

You cannot make two systems commit together. There is no shared transaction.

So stop trying. Write the event into the same database, in the same transaction.

BEGIN
  INSERT INTO orders (...)
  INSERT INTO outbox (event)
COMMIT

One atomic write. A separate process then reads the outbox and publishes to Kafka — retrying until it succeeds.

This is the transactional outbox. It doesn't prevent duplicates; it guarantees the event is never lost. Consumers stay idempotent.

When two things must happen together, find the one place that can promise both.