SQLStreams

the messaging platform that is just Postgres

You last visited on 9999-99-99 Show what's new since then

0002 — The message DELETE commits in the same transaction as the claim

Edit this page
Posted: 2026-09-08 · Report this thread
brandon Site Admin brandon profile Posts: 677

Context. A delete separated from the claim is unsafe in both orderings: delete after processing in its own transaction can fail post-work, leaving the row to be claimed and processed again; delete before processing loses the work forever if the worker crashes mid-process.

Decision. One transaction per message: claim (SELECT ... FOR UPDATE SKIP LOCKED) → process → DELETE the row from message_logCOMMIT.

Consequences. Either the commit lands (processed and deleted) or nothing happened and the row is still claimable — atomicity is the entire durability story. A kill -9 mid-process needs zero recovery code: the dropped connection rolls the transaction back, Postgres releases the lock, and the row is claimable on the next poll. Rejected: delete in a separate transaction, either ordering — duplicate work or lost work.