System Design · Senior · Question 36 of 75

How do you atomically update the database and publish an event to a queue?

Explanation

Without a transaction spanning the DB and the broker, inconsistencies are possible: the write succeeded but the event was lost (or vice versa). An outbox table records the event atomically with the change, and a relay publishes it with retries (at-least-once).

Further reading

Problem with a question

System Design · Senior · question 36

Test yourself

Take the System Design · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz