1. Pretty easy to understand and grok the problem space
2. Scratching the programmer itch of wanting something super generic that you can reuse all over the place
3. Doable with a modest effort over a reasonable scope of time
4. Built on rock solid internals (Postgres) with specific guarantees that you can lean on
Here's 7 of them just right quick:
- https://github.com/timgit/pg-boss
- https://github.com/queueclassic/queue_classic
- https://github.com/florentx/pgqueue
- https://github.com/mbreit/pg_jobs
- https://github.com/graphile/worker
- https://github.com/que-rb/que
Probably could easily find more by searching, I only spent about 5 minutes looking and grabbing the first ones I found.
I'm all for doing this kind of thing as an academic exercise, because it's a great way to learn about this problem space. But at this point if you're reinventing the Postgres job queue wheel and sharing it to this technical audience you need to probably also include why your wheel is particularly interesting if you want to grab my attention.
At some point it may become practical to bring a dedicated queue system into the stack, sure, but this can massively simplify things when you don’t need or want the additional complexity.
begin;
insert_row();
schedule_job_for_elasticsearch();
commit;
And it's guaranteed that both the row and job for Elasticsearch update are inserted.If you use a dedicated queue system them this becomes a lot more tricky:
begin;
insert_row();
schedule_job_for_elasticsearch();
commit; // Can fail, and then we have a ES job but no SQL row.
begin;
insert_row();
commit;
schedule_job_for_elasticsearch(); // Can fail, and then we have a SQL row and no job.
There are of course also situations where this doesn't apply, but this "insert row(s) in SQL and then queue job to do more with that" is a fairly common use case for queues, and in those cases this is a great choice.And as far as I can tell, this is only a perk when your two actions are mutate the collocated database and do X. For all other situations this seems like a downgrade.
Never did. The production code still uses PG based queue (which has been improved since) and pg just works perfectly fine. Might still need to go with a dedicated queue service at some point but it has been perfectly fine so far.
I guess if you already have postgres and don't want to use the cloud provider's solution. You can use this to avoid hosting another piece of infra.