Live data from Hacker News

Postgres is a great pub/sub and job server (2019)

webapp.io

141–150 of 209 posts

Re: Postgres is a great pub/sub and job server (2019)

#141
If you are interested how to implement this in Python, check out this Gist: https://gist.github.com/kissgyorgy/beccba1291de962702ea9c237...

It's really simple. I used this snippet for a real-time application which can react to any kind of change in the database instantly.

Re: Postgres is a great pub/sub and job server (2019)

#142

Earlier quoted context omitted.

I assume that is their main database for everything, not just for pub/sub. One of the big benefits of doing it that way is that you have proper transaction handling across jobs and their related data.

Come on man… you can run the whole thing off if a few Gb instance. Such a huge instance should be able to do about 100k a second!

Does postgres scale that well? I would be interested in case studies as I've not seen much achieving beyond 10k records per second.

Re: Postgres is a great pub/sub and job server (2019)

#143

Earlier quoted context omitted.

Such a server is 400$/mo, a backend developer that can confidently maintain kafka in production is significantly more expensive!

But Kafka does significantly more. And if your needs are simpler like in this case then there are dozens of smaller pub/sub/queue systems that you could compare this to.

I would say postgres does much more. What use case can only Kafka handle?

Re: Postgres is a great pub/sub and job server (2019)

#144
post #83

Earlier quoted context omitted.

This assumes that you're creating a transaction per message, which I think is not advisable.

if you care to elaborate, i'm curious -- what alternative(s) would you recommend instead of one transaction per message, and why?

The article's approach is to have a column that stores if he job has been claimed and then handles dead jobs by just having a timeout.

Re: Postgres is a great pub/sub and job server (2019)

#145
post #53

Earlier quoted context omitted.

If a job fails, the connection to the database will timeout. Postgres will rollback the transaction, which releases row locks, freeing a job to be retried. Of course, the database client and server together form a distributed system. The client might continue processing a job under the mistaken impression that it still holds the lock. Jobs still need to be idempotent, as with the streaming platforms.

This assumes that you're creating a transaction per message, which I think is not advisable.

You can also create transactions for batches of messages if you want. Same as acking batches of messages in a queue system.

Re: Postgres is a great pub/sub and job server (2019)

#146

Anybody using graphile-worker[1] in production/heavy load? It looks awesome, and I coded up some simple prototype tasks (email, sms, etc), but question how it truly scales. They claim horizontal scaling is trivial. > graphile-worker is horizontally scalable. Each instance has a customisable worker pool, this pool defaults to size 1 (only one job at a time on this worker) but depending on the nature of your tasks (i.e…

Graphile Worker maintainer here; keep in mind that postgres is not the ideal location for a job queue, so you’re going to be limited ultimately by postgres’ capabilities. I’ve seen Worker max out at around 10k jobs/second but very much YMMV - you should benchmark it for your expected use case. Personally I’d move to a dedicated job queue if I started having an average of more than 1-2k jobs per second. The majority of systems never hit anywhere near this (we very much cater to the “long tail” of job queue needs).

Regarding the horizontal scalability; that relates to if you have heavy tasks (tasks that take a second or more to execute) - you can use more instances to get higher throughput.

Hope this helps!

Re: Postgres is a great pub/sub and job server (2019)

#147

Earlier quoted context omitted.

> doing hundreds of thousands of messages per day > The postgres instance now runs on 32 cores and 128gb of memory and has scaled well. Am I the only one?

Such a server is 400$/mo, a backend developer that can confidently maintain kafka in production is significantly more expensive!

That's the job of a DevOps engineer not a backend developer attempted to be overworked.

Re: Postgres is a great pub/sub and job server (2019)

#148
post #107

Earlier quoted context omitted.

Such a server is 400$/mo, a backend developer that can confidently maintain kafka in production is significantly more expensive!

It's that much on a popular cloud platform, you can buy this for 3-4 times that amount and use it for years.

Got a 128gb 32 core xeon workstation sitting under my desk off eBay and it was $400

Re: Postgres is a great pub/sub and job server (2019)

#150
post #53

Earlier quoted context omitted.

If a job fails, the connection to the database will timeout. Postgres will rollback the transaction, which releases row locks, freeing a job to be retried. Of course, the database client and server together form a distributed system. The client might continue processing a job under the mistaken impression that it still holds the lock. Jobs still need to be idempotent, as with the streaming platforms.

This assumes that you're creating a transaction per message, which I think is not advisable.

Postgres implicitly creates a transaction for any query modifying data outside of one.

Transactions in MVCC are relatively cheap. The main resource of contention is a global txid that can disastrously wrap around if autovacuum is disabled. That process is responsible for a few other important tasks, like updating statistics for the query planner and maintaining BRIN indexes.

Post reply on HN