r/Supabase • • 1d ago

database PostgreSQL persistent task queue: concurrency, idempotency and restart recovery

/r/codereview/comments/1y6b5t7/postgresql_persistent_task_queue_concurrency/

For those using Supabase, would you recommend Supabase Queues (pgmq) or a dedicated PostgreSQL queue table for this use case? I'm particularly interested in concurrency, stale worker protection and reliable restart recovery.

1 Upvotes

11 comments sorted by

View all comments

1

u/Smooth-Vehicle547 1d ago

A claim id on its own prevents nothing, it only works if the final write checks it (update... where claim_id = $1). And what did the test actually show on the stale result? 'Potential issue' can mean a slow ack or a re-queue while the old worker is still alive, and the fix isn't the same.

1

u/fervent7 1d ago

Thank you for the clarification. A stale queue-completion issue was reproduced during our offline CI testing, but I still need to confirm the exact sequence from the test trace.

The intended correction is to make the final write conditional on the candidate identity, current claim ID, processing state and lease validity, within an atomic database operation.

We also intend to test delayed acknowledgements and reassignment while the original worker is still active as separate scenarios.

Would you recommend any additional safeguards for handling these race conditions in PostgreSQL?