Skip the Lock Entirely

A payout worker takes a distributed lock before paying a pending invoice, and the lock service has started returning intermittent errors that stall payouts. The row already has a status column with values pending and paid. What removes the need for the lock?

A

Read the row, UPDATE it, and compare the reported row count against the number of invoices still pending

B

Issue UPDATE payouts SET status='paid' WHERE id=$1 AND status='pending' RETURNING id, and send money only if a row came back

C

Open a transaction, SELECT the row, verify the status is pending, then UPDATE it and commit so the check and the write are atomic

D

Retry lock acquisition with exponential backoff and jitter until the lock service answers, so no payout is skipped