Database and event atomicity

DesignHard45 min

Your task

A microservices system has an Orders service (its own Postgres) that must, on every order change, both commit the DB change AND publish an event to Kafka for downstream services (inventory, notifications, analytics). Today it writes to the DB and then publishes to Kafka in app code; sometimes the DB commits but the Kafka publish fails (or vice versa), so downstream state diverges from the DB and inventory drifts. ~5k order changes/sec. Design how to make the DB change and the event publish atomic and exactly-once-effective downstream.

It covers

  • Microservices
  • Outbox
  • Dual write