SteelReed

Search

Search posts, questions…

Messaging & KafkaQuestion 3 / 21

Junior

What do at-most-once, at-least-once and exactly-once mean?

Short answer

At-most-once can lose messages, at-least-once can process them twice, exactly-once means the final effect is as if each message were processed once. The default choice is at-least-once + an idempotent consumer.

Commit firstProcess firstSame transaction+ idempotent consumerReceive messageWhen to commit?Crash: lost, at-most-onceCrash: repeated,at-least-onceExactly-onceEffectively exactly-once

3 points to say:

  1. At-most-once: commit first, process later, a crash loses it; at-least-once: the reverse, a crash repeats it.
  2. True exactly-once needs state and offset in one transaction: Kafka transactions, or storing the offset in the same DB transaction.
  3. Default to at-least-once + idempotency; external side effects (email, payment APIs) need an idempotency key.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.