System design · interactive
Delivery guarantees and duplicates
A consumer reads five payment messages from a queue and saves its position (the offset) as it goes. It crashes once, right after charging pay-3. When it saves its position decides whether a message is lost or done twice.
- pay-1 ×1
- pay-2 ×1
- pay-3 ×2
- pay-4 ×1
- pay-5 ×1
- 1pay-1: charge 10
- 2commit offset 1
- 3pay-2: charge 20
- 4commit offset 2
- 5pay-3: charge 30
- 6crash before committing
- 7restart from offset 2: pay-3 is delivered again
- 8pay-3: charge 30
- 9commit offset 3
- 10pay-4: charge 40
- 11commit offset 4
- 12pay-5: charge 50
- 13commit offset 5
Charged 180 · should be 150
Nothing is lost, but pay-3 is processed twice after the restart: charged 180 instead of 150.
Consumer
Step 2 of 4 · read left to right
In production
Tools and technologies
Queues give you at-least-once; consumers make it safe.
Not tied to one language — use these names when you search docs or design a system.