Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In many scenarios a DB/SQL-backed queue is far superior to the fancy queue solutions such as RabbitMQ because it gives you instantaneous granular control over 'your queue' (since it is the result set of your query to reserve the next job).

Historically people like to point out the common locking issues etc... with SQL but in modern datbases you have a good number of tools to deal with that ("select for update nowait").

If you think about it a queue is just a performance optimisation (it helps you get the 'next' item in a cheap way, that's it).

So you can get away with "just a db" for a long time and just query the DB to get the next job (with some 'reservations' to avoid duplicate processing).

At some point you may overload the DB if you have too many workers asking the DB for the next job. At that point you can add a queue to relieve that pressure.

This way you can keep a super dynamic process by periodically selecting 'next 50 things to do' and injecting those job IDs in the queue.

This gives you the best of both worlds because you can maintain granular control of the process by not having large queues (you drip feed from DB to queue in small batches) and the DB is not overly burdened.



+1 to this. I'm just as wary to recommend using a DB as a queue as the next person, but it is a very common pattern at my company.

DB queues allow easy prioritization, blocking, canceling, and other dynamic queued job controls that basic FIFO queues do not. These are all things that add contention to the queue operations. Keep your queues as dumb as you possibly can and go with FIFO if you can get away with it, but DB queues aren't the worst design choice.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: