CS FundamentalsVery hardProduct-company system-design interview

A message broker delivers each message at least once, so consumers sometimes see duplicates (for example after a crash before an ack). A consumer credits a wallet on each 'payment received' message. How should it be designed?

  1. A. Ask the broker to switch to at-most-once delivery
  2. B. As an idempotent consumer: record processed message ids (or use a unique key in the same transaction) and skip duplicates
  3. C. Process messages twice to be safe
  4. D. Acknowledge messages before processing them

Correct answer: B. As an idempotent consumer: record processed message ids (or use a unique key in the same transaction) and skip duplicates

With at-least-once delivery, effects must be idempotent or deduplicated. At-most-once (or acking before processing) can lose payments when a consumer crashes, which is worse.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic