All jobs / Backend developer / Distributed Systems
Backend developer interview question · 3–5 years
The interviewer asks: “The outbox publisher crashed after sending but before marking sent. What happens?” Strongest answer?
The strongest answer
It will send again. That's why consumers are idempotent and why the message carries a stable event id. I don't try to make the publisher exactly-once in-process.
Why it works
Exactly. At-least-once plus an event id is the robust design. Exactly-once is a property you approach with idempotent consumers, not a flag on the producer.
What a good answer covers
- Publisher duplicates are expected.
- Stable event id + idempotent consumer.
- Don't mark sent before send.
- Don't go back to in-memory dual-write.
Answers that fall short
- Close, but not the strongest: I wrap send and mark-sent in a distributed transaction with the broker.
A 2PC with the broker is the complexity you left 2PC to avoid. Don't bring it back for the publisher. - Weak: I mark sent before sending so this can't happen.
Mark-before-send drops the event if send fails. That's at-most-once loss. - Red flag: I skip the outbox and publish from memory after commit.
In-memory after commit is the dual-write bug again. The outbox exists so a crash doesn't eat the event — duplicates are OK.
Who gets asked this
More Distributed Systems questions
- The interviewer asks: “Recommendations are down. Checkout still needs to work. What do you do?” Strongest…
- The interviewer asks: “We're adding a search index. Can the API write DB and Elasticsearch in one request?”…
- What happened, and what actually protects the write?
- The interviewer asks: “Active-active in two regions — what's the hard part?” Strongest answer?
- The interviewer asks: “A client retries POST /payments because of a timeout. How do you not charge twice?”…
- The interviewer asks: “A downstream HTTP call timed out. Do you retry?” Strongest answer?
- The interviewer asks: “Your HTTP client has no timeout. What's the risk?” Strongest answer?
- A RabbitMQ consumer acknowledges each message as soon as it arrives and then processes it. Messages go…