Part 1 · 1 chapters · ~8 min
Delivery Semantics and Idempotent Consumers
At-most-once, at-least-once and the myth of exactly-once delivery, idempotent handlers (dedupe tables, unique constraints, conditional updates, natural idempotency), ordering and versioned updates, visibility timeouts and leases, and testing duplicate delivery.
3
Three semantics, one practical answer
code
-- an idempotent handler: the dedupe record and the effect commit together
BEGIN;
INSERT INTO processed_messages (message_id) VALUES ($1) ON CONFLICT DO NOTHING RETURNING message_id;
-- if no row returned: already processed → COMMIT and acknowledge
UPDATE payouts SET state = 'completed' WHERE id = $2 AND state IN ('submitted', 'unknown'); -- conditional: safe to repeat
COMMIT;
-- then acknowledge the messageDELIVERY SEMANTICS
what can happen to a message, and what you must build
swipe the figure sideways, or tap expand for full screen
1/5
at most once
Acknowledging first means a crash mid-processing loses the work.
may lose messagesmetrics, telemetry only