Live data from Hacker News

System design hack: Postgres is a great pub/sub and job server

layerci.com

11–20 of 162 posts

Re: System design hack: Postgres is a great pub/sub and job server

#12
post #11

If you're working with Ruby I have had good experiences with Que[1], which implements a pattern similar to the OP using advisory locks. [1]: https://github.com/que-rb/que

Is there a similar library in Python?

I really like the look of this approach, but don't want to build it myself if I can avoid it.

Re: System design hack: Postgres is a great pub/sub and job server

#13
post #12
post #11

If you're working with Ruby I have had good experiences with Que[1], which implements a pattern similar to the OP using advisory locks. [1]: https://github.com/que-rb/que

Is there a similar library in Python? I really like the look of this approach, but don't want to build it myself if I can avoid it.

https://pypi.org/project/pq/ looks similar, although it looks like they use `SKIP LOCKED` instead of advisory locks. I'm not sure what the tradeoff is.

Re: System design hack: Postgres is a great pub/sub and job server

#14
Can someone share their experience with scaling pg's NOTIFY and LISTEN?

The use case I have in mind has a lot of logically separate queues. Is it better for each queue to have its own channel (so subscribers can listen to only the queue they need) or have all queues notify a global channel (and have subscribers filter for messages relevant to them). I am mainly confused about whether I need a dedicated db connection per LISTEN query and also how many channels is too much.

Re: System design hack: Postgres is a great pub/sub and job server

#15
post #14

Can someone share their experience with scaling pg's NOTIFY and LISTEN? The use case I have in mind has a lot of logically separate queues. Is it better for each queue to have its own channel (so subscribers can listen to only the queue they need) or have all queues notify a global channel (and have subscribers filter for messages relevant to them). I am mainly confused about whether I need a dedicated db connection…

You can listen multiple times per database connection.

I'm not sure what the maximum scale is, but I've never hit it.

Re: System design hack: Postgres is a great pub/sub and job server

#16
post #11

If you're working with Ruby I have had good experiences with Que[1], which implements a pattern similar to the OP using advisory locks. [1]: https://github.com/que-rb/que

I'll second this recommendation. It's great because it just snaps onto your backups for your regular database and you can query on it if you need to.

Re: System design hack: Postgres is a great pub/sub and job server

#17
post #11

If you're working with Ruby I have had good experiences with Que[1], which implements a pattern similar to the OP using advisory locks. [1]: https://github.com/que-rb/que

https://github.com/timgit/pg-boss for node, https://github.com/mbuhot/ecto_job for elixir.

I wish all these libraries agreed on a common schema >_<

Re: System design hack: Postgres is a great pub/sub and job server

#20
post #2

Isn't hijacking a DB as a "distributed" message queue a pretty well trodden path? Enterprises have been doing this for decades.

This pattern falls down if you need to poll the database, because if you have 3 queues and 100 workers you're making 300 queries per poll interval. The feature of postgres that makes this viable in comparison to most other databases is the "channel"

What if your listeners crashed/were down at the time of the `PUB` message? Does this mean the message falls into oblivion (since it will never receive a reply/ACK/get worked on)?
Post reply on HN