zlacker

[parent] [thread] 3 comments
1. crypto+(OP)[view] [source] 2019-05-27 23:20:47
You'd have the same problem with SQS, wouldn't you. The act of dequeueing does not guarantee that the process that received a message will not fail to perform it.

If you want a reliable system along those lines than you need to use SKIP LOCKED to SELECT one row to lock, then process it, and then DELETE the row. If your process dies then the lock will be release. You still have a new flavor of the same problem: you might process a message twice because the process might die in between completing processing and deleting the row. You could add complexity: first use SKIP LOCKED to SELECT one row to UPDATE to mark in-progress and LOCK the row, then later if the process dies another can go check if the job was performed (then clean the garbage) or not (pick and perform the job) -- a two-phase commit, essentially.

Factor out PG, and you'll see that the problem similar no matter the implementation.

replies(2): >>soroko+TE >>derefr+w28
2. soroko+TE[view] [source] 2019-05-28 09:32:37
>>crypto+(OP)
With SQS, the act of dequeueing makes the mesage invisible to other consumers for a predefined time period. The consumer can ack the mesage once the procesing is completed resulting in the message being deleted. If the consumers fails to do so - the mesage will eventually become elligible to be processed by another consumer,
replies(1): >>crypto+nj1
◧◩
3. crypto+nj1[view] [source] [discussion] 2019-05-28 15:21:14
>>soroko+TE
I described, in the message you're responding to, how to do the same thing with SKIP LOCKED.
4. derefr+w28[view] [source] 2019-05-30 23:12:44
>>crypto+(OP)
> you might process a message twice because the process might die in between completing processing and deleting the row

The very handy thing about the setup described, is that your data tables are part of the same MVCC world-state as your message queue. So you do all the work for the job, in the context of the same MVCC transaction that is holding the job locked; and anything that causes the job to fail, will fail the entire transaction, and thus rollback any changes that the job's operation made to the data.

[go to top]