3 ms·
If you don't need high throughput and otherwise don't have a reason to add a separate technology to the stack just to have a queue, SQL can make a great, simple
by vkjv 9y ago
If you don't need high throughput and otherwise don't have a reason to add a separate technology to the stack just to have a queue, SQL can make a great, simple and reliable queue!
* Postgresql and Oracle with skip locked
* MS SQL Server with readpast
* DB2 with skip locked data
If you use MySQL, it's going to be a bit more difficult.
- burkemw3 9y agoI hadn't heard of skip locked before, and very much enjoyed this article walking through it for postgres: https://blog.2ndquadrant.com/what-is-select-skip-locked-for-in-postgresql-9-5/ https://blog.2ndquadrant.com/what-is-select-skip-locked-for-...
- swah 9y agoLove the headline "Most work queue implementations in SQL are wrong". That kind of stuff makes me read an article... This short screencast was also very helpful https://www.pgcasts.com/episodes/7/skip-locked/ https://www.pgcasts.com/episodes/7/skip-locked/
- monksy 9y agoUsing the database as a queue is an anti-pattern. There used to be an entire blog series about why this is the case. However, I can't find it at the moment.
- eternalvision 9y agoWith MySQL, there's a fairly simple trick you can do to build a queue. Set a temp var to null, run an update with a select subquery to update state of next row(s), then select that var to get your queue row pk's.