Oh My Algorithm
Concept Guideat-least-once · at-most-once

Not Losing Messages (Delivery Guarantees)

When you record how far you've read decides whether you lose messages or process them twice. Commit before doing the work and a crash mid-processing means that message is never read again (at-most-once); commit after and a crash means the same message is read once more (at-least-once). Kafka usually takes the latter and makes the processing side idempotent so duplicates are harmless.

01 Concept at a Glance

Interactive Step-by-Step
Commit first · you can lose (at-most-once)
← earlier orders · later orders →
Orders partition
🧾Order A
🧾Order B
🧾Order C
🧾Order D
01234
▲reads next
▲ = where it reads next · nothing processed yet

Four orders are queued and the consumer is about to read B. ▲ points at B.

Logic Node1 / 5
Process first · you can duplicate (at-least-once)
← earlier orders · later orders →
Orders partition
🧾Order A
🧾Order B
🧾Order C
🧾Order D
01234
▲reads next
▲ = where it reads next · nothing processed yet

Same situation, only the order is swapped. ▲ is pointing at B.

Logic Node1 / 6

02 Understand It Simply

For Everyone
🔑Analogy

Like when you sign for a delivery. Sign before opening the box and you can't take it back if it's wrong; check first and sign after, and if you collapse just before signing, the next person checks the same box again.

💡In Plain Words

Commit first and any message you died on is skipped forever (loss).

Process first and a crash before the commit means reprocessing it after restart (duplication).

Removing both requires the work and the commit to be one transaction, which is expensive.

So in practice you pick at-least-once and make processing idempotent — same result whether a message arrives once or twice.

📍Where It's Used
  • Designing flows where loss is unacceptable (payments
  • orders)
  • designing idempotency keys against duplicates
  • and trading commit interval against recovery time

03 Frequently Asked Questions

FAQ
What is Not Losing Messages (Delivery Guarantees)?+

When you record how far you've read decides whether you lose messages or process them twice. Commit before doing the work and a crash mid-processing means that message is never read again (at-most-once); commit after and a crash means the same message is read once more (at-least-once). Kafka usually takes the latter and makes the processing side idempotent so duplicates are harmless.

Where is Not Losing Messages (Delivery Guarantees) used?+

Designing flows where loss is unacceptable (payments, orders), designing idempotency keys against duplicates, and trading commit interval against recovery time.

What's a simple analogy for Not Losing Messages (Delivery Guarantees)?+

Like when you sign for a delivery. Sign before opening the box and you can't take it back if it's wrong; check first and sign after, and if you collapse just before signing, the next person checks the same box again.

Guide Progress0%