All jobs / Backend developer / Distributed Systems
Backend developer interview question · 3–5 years
The interviewer asks: “How do you publish an event only if the order row actually committed?” Strongest answer?
The strongest answer
Transactional outbox: write the row and an outbox record in the same transaction; a publisher drains the outbox. No commit without the event, no event without the commit.
Why it works
Exactly. Dual-write (DB and broker as two commits) will desync. The outbox makes the event part of the same atomic unit; at-least-once drain + idempotent consumers finish the story.
What a good answer covers
- Outbox sits in the same DB transaction.
- A worker publishes after commit.
- Consumers stay idempotent.
- Don't dual-write and hope.
Answers that fall short
- Close, but not the strongest: Publish to the broker, then write the row — if the DB fails I'll compensate.
Broker-first leaves events for rows that never existed. Compensating that in the request path is a saga you didn't plan. - Weak: Write the row, then publish; if publish fails the user can retry.
DB-then-publish loses the event on a crash between the two. That's the bug the outbox exists for. - Red flag: Catch publish errors after commit and return 201 anyway so checkout feels fast.
201 without the event means downstream never billed or emailed. That's a silent split brain.
Who gets asked this
More Distributed Systems questions
- The interviewer asks: “We need “all services succeed or none” across order, inventory and billing. What do…
- The interviewer asks: “Consumers are slow. The publisher is fast. What do you do?” Strongest answer?
- The interviewer asks: “A message fails every time. The consumer keeps retrying. What now?” Strongest answer?
- Order-status events for the same order are arriving out of order at the consumer. The topic has twelve…
- The interviewer asks: “The user saves a profile then immediately GETs it from another region and sees the old…
- The interviewer asks: “A dependency is failing. How do you stop your service from dying with it?” Strongest…
- The interviewer asks: “The outbox publisher crashed after sending but before marking sent. What happens?”…
- The interviewer asks: “Recommendations are down. Checkout still needs to work. What do you do?” Strongest…