TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: PgQueuer – Transform PostgreSQL into a Job Queue

376 pointsby jeeybee9 months ago
PgQueuer is a minimalist, high-performance job queue library for Python, leveraging the robustness of PostgreSQL. Designed for simplicity and efficiency, PgQueuer uses PostgreSQL's LISTEN/NOTIFY to manage job queues effortlessly.

28 comments

westurner9 months ago
Does the celery SQLAlchemy broker support PostgreSQL&#x27;s LISTEN&#x2F;NOTIFY features?<p>Similar support in SQLite would simplify testing applications built with celery.<p>How to add table event messages to SQLite so that the SQLite broker has the same features as AMQP? Could a vtable facade send messages on tablet events?<p>Are there sqlite Triggers?<p>Celery &gt; Backends and Brokers: <a href="https:&#x2F;&#x2F;docs.celeryq.dev&#x2F;en&#x2F;stable&#x2F;getting-started&#x2F;backends-and-brokers&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;docs.celeryq.dev&#x2F;en&#x2F;stable&#x2F;getting-started&#x2F;backends-...</a><p>&#x2F;? sqlalchemy listen notify: <a href="https:&#x2F;&#x2F;www.google.com&#x2F;search?q=sqlalchemy+listen+notify" rel="nofollow">https:&#x2F;&#x2F;www.google.com&#x2F;search?q=sqlalchemy+listen+notify</a> :<p>asyncpg.Connection.add_listener<p>sqlalchemy.event.listen, @listen_for<p>psychopg2 conn.poll(), while connection.notifies<p>psychopg2 &gt; docs &gt; advanced &gt; Advanced notifications: <a href="https:&#x2F;&#x2F;www.psycopg.org&#x2F;docs&#x2F;advanced.html#asynchronous-notifications" rel="nofollow">https:&#x2F;&#x2F;www.psycopg.org&#x2F;docs&#x2F;advanced.html#asynchronous-noti...</a><p>PgQueuer.db, PgQueuer.listeners.add_listener; asyncpg add_listener: <a href="https:&#x2F;&#x2F;github.com&#x2F;janbjorge&#x2F;PgQueuer&#x2F;blob&#x2F;main&#x2F;src&#x2F;PgQueuer&#x2F;db.py">https:&#x2F;&#x2F;github.com&#x2F;janbjorge&#x2F;PgQueuer&#x2F;blob&#x2F;main&#x2F;src&#x2F;PgQueuer...</a><p>asyncpg&#x2F;tests&#x2F;test_listeners.py: <a href="https:&#x2F;&#x2F;github.com&#x2F;MagicStack&#x2F;asyncpg&#x2F;blob&#x2F;master&#x2F;tests&#x2F;test_listeners.py">https:&#x2F;&#x2F;github.com&#x2F;MagicStack&#x2F;asyncpg&#x2F;blob&#x2F;master&#x2F;tests&#x2F;test...</a><p>&#x2F;? sqlite LISTEN NOTIFY: <a href="https:&#x2F;&#x2F;www.google.com&#x2F;search?q=sqlite+listen+notify" rel="nofollow">https:&#x2F;&#x2F;www.google.com&#x2F;search?q=sqlite+listen+notify</a><p>sqlite3 update_hook: <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;c3ref&#x2F;update_hook.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;c3ref&#x2F;update_hook.html</a>
airocker9 months ago
We use listen notify extensively and it is great. The things it lacks most for us is guaranteed single recipient. All subscribers get all notifications which leads to problems in determining who should act on the message n our case.
评论 #41295297 未加载
评论 #41298176 未加载
CowOfKrakatoa9 months ago
How does LISTEN&#x2F;NOTIFY compare to using select for update skip locked? I thought listen&#x2F;notify can lose queue items when the process crashes? Is that true? Do you need to code for those cases in some manner?
评论 #41285278 未加载
评论 #41286474 未加载
评论 #41285951 未加载
评论 #41294867 未加载
rtpg9 months ago
I am going to go the other direction on this... to anyone reading this, please consider using a backend-generic queueing system for your Python project.<p>Why? Mainly because those systems offer good affordances for testing and running locally in an operationally simple way. They also tend to have decent default answers for various futzy questions around disconnects at various parts of the workflow.<p>We all know Celery is a buggy pain in the butt, but rolling your own job queue likely ends up with you just writing a similary-buggy pain in the butt. We&#x27;ve already done &quot;Celery but simpler&quot;, it&#x27;s stuff like Dramatiq!<p>If you have backend-specific needs, you won&#x27;t listen to this advice. But think deeply how important your needs are. Computers are fast, and you can deal with a lot of events with most systems.<p>Meanwhile if you use a backend-generic system... well you could write a backend using PgQueuer!
评论 #41291794 未加载
评论 #41286758 未加载
评论 #41291656 未加载
odie55339 months ago
I&#x27;ve been referring to this post about issues with Celery: <a href="https:&#x2F;&#x2F;docs.hatchet.run&#x2F;blog&#x2F;problems-with-celery">https:&#x2F;&#x2F;docs.hatchet.run&#x2F;blog&#x2F;problems-with-celery</a><p>Does PgQueuer address any of them?
评论 #41289713 未加载
ijustlovemath9 months ago
You could even layer in PostgREST for a nice HTTP API that is available from any language!
评论 #41289678 未加载
martinald9 months ago
Any suggestions for something like this for dotnet?
评论 #41285931 未加载
评论 #41286757 未加载
评论 #41286448 未加载
fijiaarone9 months ago
You can make anything that stores data into a job queue.
评论 #41286099 未加载
nifal_adam9 months ago
It looks like PgQueuer integrates well with Postgres RPC calls, triggers, and cronjobs (via pg_cron). Interesting, will check it out.
rgbrgb9 months ago
Cool, congrats on releasing. Have you seen graphile worker? Wondering how this compares or if you&#x27;re building for different use-cases.
评论 #41288327 未加载
评论 #41286735 未加载
_joel9 months ago
Broadcaster is one we use in production for PUB&#x2F;SUB stuff with OPA&#x2F;OPAL. <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;broadcaster&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;broadcaster&#x2F;</a>
bfelbo9 months ago
How does this compare to the popular Graphile Worker library?<p><a href="https:&#x2F;&#x2F;github.com&#x2F;graphile&#x2F;worker">https:&#x2F;&#x2F;github.com&#x2F;graphile&#x2F;worker</a>
评论 #41290578 未加载
piyushtechsavy9 months ago
Although I am more of a MySQL guy, I have been exploring PostgreSQL from sometime. Seems it has lot of features out of box.<p>This is very interesting tool.
mslot9 months ago
Nice! Seems to be pretty well-crafted.
CRConrad9 months ago
The name is perhaps slightly fraught with risk... I missed the second &#x27;u&#x27;, at first, so I misread it.
joseferben9 months ago
for typescript there is pg-boss, works great for us
worik9 months ago
Why so much code for Avery simple concept<p>One table.<p>Producer writes Co sumer reads<p>A very good idea
cklee9 months ago
I’ve been thinking about the potential for PostgreSQL-backed job queue libraries to share a common schema. For instance, I’m a big fan of Oban in Elixir: <a href="https:&#x2F;&#x2F;github.com&#x2F;sorentwo&#x2F;oban">https:&#x2F;&#x2F;github.com&#x2F;sorentwo&#x2F;oban</a><p>Given that there are many Sidekiq-compatible libraries across various languages, it might be beneficial to have a similar approach for PostgreSQL-based job queues. This could allow for job processing in different languages while maintaining compatibility.<p>Alternatively, we could consider developing a core job queue library in Rust, with language-specific bindings. This would provide a robust, cross-language solution while leveraging the performance and safety benefits of Rust.
评论 #41285821 未加载
评论 #41285276 未加载
评论 #41285671 未加载
评论 #41285727 未加载
评论 #41287831 未加载
评论 #41291711 未加载
评论 #41285238 未加载
评论 #41289539 未加载
评论 #41290568 未加载
samwillis9 months ago
This looks like a great task queue, I&#x27;m a massive proponent of &quot;Postgres is all you need&quot; [0] and doubling down on it with my project that takes it to the extreme.<p>What I would love is a Postgres task queue that does multi-step pipelines, with fan out and accumulation. In my view a structured relational database is a particularly good backend for that as it inherently can model the structure. Is that something you have considered exploring?<p>The one thing with listen&#x2F;notify that I find lacking is the max payload size of 8k, it somewhat limits its capability without having to start saving stuff to tables. What I would really like is a streaming table, with a schema and all the rich type support... maybe one day.<p>0: <a href="https:&#x2F;&#x2F;www.amazingcto.com&#x2F;postgres-for-everything&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.amazingcto.com&#x2F;postgres-for-everything&#x2F;</a>
评论 #41287838 未加载
评论 #41285246 未加载
评论 #41287262 未加载
评论 #41286133 未加载
评论 #41290575 未加载
aflukasz9 months ago
BTW: Good PostgresFM episode on implementing queues in Postgres, various caveats etc: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=mW5z5NYpGeA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=mW5z5NYpGeA</a> .
评论 #41285942 未加载
评论 #41290570 未加载
kdunglas9 months ago
The Symfony framework (PHP) provides a similar feature, which also relies on LISTEN&#x2F;NOTIFY and FOR UPDATE SKIP LOCKED: <a href="https:&#x2F;&#x2F;symfony.com&#x2F;doc&#x2F;current&#x2F;messenger.html#doctrine-transport" rel="nofollow">https:&#x2F;&#x2F;symfony.com&#x2F;doc&#x2F;current&#x2F;messenger.html#doctrine-tran...</a><p>It also supports many other backends including AMQP, Beanstalkd, Redis and various cloud services.<p>This component, called Messenger, can be installed as a standalone library in any PHP project.<p>(Disclaimer: I’m the author of the PostgreSQL transport for Symfony Messenger).
评论 #41289275 未加载
gmag9 months ago
You might also want to look at River (<a href="https:&#x2F;&#x2F;github.com&#x2F;riverqueue&#x2F;river">https:&#x2F;&#x2F;github.com&#x2F;riverqueue&#x2F;river</a>) for inspiration as they support scheduled jobs, etc.<p>From an end-user perspective, they also have a UI which is nice to have for debugging.
评论 #41286682 未加载
评论 #41288889 未加载
评论 #41286598 未加载
评论 #41290580 未加载
_medihack_9 months ago
There is also Procrastinate: <a href="https:&#x2F;&#x2F;procrastinate.readthedocs.io&#x2F;en&#x2F;stable&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;procrastinate.readthedocs.io&#x2F;en&#x2F;stable&#x2F;index.html</a><p>Procrastinate also uses PostgreSQL&#x27;s LISTEN&#x2F;NOTIFY (but can optionally be turned off and use polling). It also supports many features (and more are planned), like sync and async jobs (it uses asyncio under the hood), periodic tasks, retries, task locks, priorities, job cancellation&#x2F;aborting, Django integration (optional).<p>DISCLAIMER: I am a co-maintainer of Procrastinate.
评论 #41289492 未加载
评论 #41289034 未加载
评论 #41290590 未加载
评论 #41286795 未加载
bdcravens9 months ago
Good Job does the same for Rails<p><a href="https:&#x2F;&#x2F;github.com&#x2F;bensheldon&#x2F;good_job">https:&#x2F;&#x2F;github.com&#x2F;bensheldon&#x2F;good_job</a>
评论 #41287634 未加载
评论 #41288234 未加载
评论 #41290084 未加载
评论 #41290589 未加载
mads_quist9 months ago
I really like the emergence of simple queuing tools for robust database management systems. Keep things simple and remove infrastructure complexity. Definitely a +1 from me!<p>For handling straightforward asynchronous tasks like sending opt-in emails, we&#x27;ve developed a similar library at All Quiet for C# and MongoDB: <a href="https:&#x2F;&#x2F;allquiet.app&#x2F;open-source&#x2F;mongo-queueing" rel="nofollow">https:&#x2F;&#x2F;allquiet.app&#x2F;open-source&#x2F;mongo-queueing</a><p>In this context:<p><pre><code> LISTEN&#x2F;NOTIFY in PostgreSQL is comparable to MongoDB&#x27;s change streams. SELECT FOR UPDATE SKIP LOCKED in PostgreSQL can be likened to MongoDB&#x27;s atomic read&#x2F;update operations.</code></pre>
评论 #41320717 未加载
评论 #41292919 未加载
jackbravo9 months ago
Most of the small python alternatives I&#x27;ve seen use Redis as backend:<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;rq&#x2F;rq">https:&#x2F;&#x2F;github.com&#x2F;rq&#x2F;rq</a> - <a href="https:&#x2F;&#x2F;github.com&#x2F;coleifer&#x2F;huey">https:&#x2F;&#x2F;github.com&#x2F;coleifer&#x2F;huey</a> - <a href="https:&#x2F;&#x2F;github.com&#x2F;resque&#x2F;resque">https:&#x2F;&#x2F;github.com&#x2F;resque&#x2F;resque</a>
评论 #41292915 未加载
redskyluan9 months ago
there seems to be a big hype to adapt pg into any infra. I love PG but this seems not be right thing.
评论 #41286596 未加载
评论 #41285805 未加载
评论 #41285980 未加载
评论 #41285572 未加载
评论 #41286581 未加载
评论 #41289281 未加载
est9 months ago
The most simple job queue in MySQL:<p><pre><code> update job_table set key=value where ... limit 1 </code></pre> It&#x27;s simple and atomic. Unfortunately PG doesn&#x27;t allow `update ... limit` syntax
评论 #41288225 未加载
评论 #41290583 未加载