Skip to content
StackDecode
System Design
9. Message Queues and Event-Driven SystemsAnimated

Exactly-Once Processing

Each message affects state exactly once.

The idea

Achieved with idempotent consumers, transactions or deduplication, since delivery itself can repeat.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

ProducerBrokerConsumersend msg id=9 (producer id + sequence)
  • current message
  • earlier
  • failure or attack

The broker deduplicates retries by producer id and sequence number.

step:
1/6
from:
Producer
to:
Broker
1/6

Time runs downward. Solid arrows are requests, dashed arrows are replies.

Step by step

  1. 1Assign each message an id
  2. 2Process and record the id atomically
  3. 3Redeliveries are detected
  4. 4Effects happen once

Where it is used

Payments and counters.

Watch out for

Costs throughput, and only works within a controlled boundary.

Related