Use the transactional outbox pattern: write the event into an outbox table in the same transaction as the state change, then have a separate relay poll or tail the log and publish it, marking it sent. That way there is one commit, so you can never have a row without an event or an event without a row. The relay gives at least once delivery, so consumers still need to be idempotent.
Why interviewers ask this
The dual write problem is one of the defining failure modes of distributed systems, and lots of candidates have never named it. The interviewer wants to see that you recognize publishing after commit can lose events and publishing before commit can invent them. Knowing the outbox, and that change data capture is the same idea driven off the write ahead log, signals real event driven experience.
How to structure your answer
- Name the dual write problem and both directions it fails.
- Describe the outbox mechanically: one transaction, separate relay.
- Mention change data capture as the log based variant.
- Note the consequences: ordering, at least once, outbox cleanup.
Example answer
The trap is that a database commit and a broker publish are two separate systems, so any ordering you pick has a failure mode. Publish first and the transaction can roll back, so consumers act on something that never happened. Commit first and the process can die before publishing, so the event is lost and nothing retries it. The outbox pattern removes the gap: the event row is inserted into an outbox table inside the same transaction as the business change, so either both land or neither does. Then a relay reads unsent rows in order and publishes them, marking them sent, and if it crashes mid publish it just republishes, which is why consumers must be idempotent. If I am on Postgres and want less polling, I use change data capture off the write ahead log with something like Debezium, which is the same guarantee with less bespoke code. The operational details worth planning are pruning the outbox and monitoring relay lag, because an outbox that stops draining looks completely healthy from the application side.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you monitor that the relay is keeping up?
- What ordering guarantees does the outbox actually give you?
- When would you pick change data capture over an application written outbox?
Related backend developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions