Really unimpressed with so many people thinking it's OK to shoehorn their database as a message queue. Use the right tool for the job.
Our industry is full of shysters pushing their own technology. Time and again, it turns out that a RDBMS will handle that job just fine. That's really the premise of this article. So please, go on and back up your bold statements with some specifics. Why specifically is it not OK to use a database as a message queue?
Choose Postgres queue technology
101–110 of 369 posts
Re: Choose Postgres queue technology
#102We process around 1 million events a day using a queue like this in Postgres, and have processed over 400 million events since the system this is used in went live. Only issue we've had was slow queries due to the table size, as we keep an archive of all the events processed, but some scheduled vacuums every so often kept that under control.
Active Queue table and then archive jobs to a JobDone table? I do that. Queue table is small but archive goes back many months
Re: Choose Postgres queue technology
#103Earlier quoted context omitted.
It seems strictly worse to use ORDER BY in this case, since if you're using SKIP LOCKED you should be doing parallel processing anyway, and if you're doing parallel processing, ordering is already going out the window.
Parallel or not, the order is of importance in any queue system.
Re: Choose Postgres queue technology
#104We process around 1 million events a day using a queue like this in Postgres, and have processed over 400 million events since the system this is used in went live. Only issue we've had was slow queries due to the table size, as we keep an archive of all the events processed, but some scheduled vacuums every so often kept that under control.
Active Queue table and then archive jobs to a JobDone table? I do that. Queue table is small but archive goes back many months
Re: Choose Postgres queue technology
#105We process around 1 million events a day using a queue like this in Postgres, and have processed over 400 million events since the system this is used in went live. Only issue we've had was slow queries due to the table size, as we keep an archive of all the events processed, but some scheduled vacuums every so often kept that under control.
Re: Choose Postgres queue technology
#106Earlier quoted context omitted.
It seems strictly worse to use ORDER BY in this case, since if you're using SKIP LOCKED you should be doing parallel processing anyway, and if you're doing parallel processing, ordering is already going out the window.
Parallel or not, the order is of importance in any queue system.
You can use locks to effectively break the queue into sub queues so that each sub queue is only being processed by 1 worker. Then you can order that sub queue.
Re: Choose Postgres queue technology
#107Re: Choose Postgres queue technology
#108I wish the industry was even half as concerned with efficiency as it was with scale. Bitcoin? Electron? 5MB web pages? 5/10/25GB downloads to run 20yr old CD-sized games on modern software?
Re: Choose Postgres queue technology
#109Earlier quoted context omitted.
I've done even simpler without locks (as no transaction logic), where I select a row, and then try to update a field about it being taken. If 1 row is affected, it's mine. If 0, someone else did it before me and I select a new row. I've used this for tasks at big organizations without issue. No need for any special deployments or new infra. Just spin up a few worker threads in your app. Perhaps a thread to reset aban…
I've done the same with MongoDB with findOneAndModify, simple and solid
Re: Choose Postgres queue technology
#110For several projects I’ve opted for the even dumber approach, that works out of the box with every ORM/Query DSL framework in every language: using a normal table with SELECT FOR UPDATE SKIP LOCKED https://www.pgcasts.com/episodes/the-skip-locked-feature-in-... It’s not “web scale” but it easily extends to several thousand background jobs in my experience
I recently published a manifesto and code snippets for exactly this in Postgres! delete from task where task_id in ( select task_id from task order by random() -- use tablesample for better performance for update skip locked limit 1 ) returning task_id, task_type, params::jsonb as params [1] https://taylor.town/pg-task