Earlier quoted context omitted.
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)?
System design hack: Postgres is a great pub/sub and job server
21–30 of 162 posts
Re: System design hack: Postgres is a great pub/sub and job server
#22Re: System design hack: Postgres is a great pub/sub and job server
#23Used the "FOR UPDATE SKIP LOCKED LIMIT 1" trick to implement a job server in PG a few years ago for the first time. It's a great solution.
Can you show what your schema for your job table looked like?
Re: System design hack: Postgres is a great pub/sub and job server
#24Earlier quoted context omitted.
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)?
The pattern I follow is that workers immediately poll once when they start - this means that when your workers restart after crashing, they'll pick up any missing jobs.
Re: System design hack: Postgres is a great pub/sub and job server
#25Used the "FOR UPDATE SKIP LOCKED LIMIT 1" trick to implement a job server in PG a few years ago for the first time. It's a great solution.
Re: System design hack: Postgres is a great pub/sub and job server
#26Earlier quoted context omitted.
The pattern I follow is that workers immediately poll once when they start - this means that when your workers restart after crashing, they'll pick up any missing jobs.
I'm not seeing how this recovers from the failure scenario where a worker grabbed an event and then immediately crashed.
Re: System design hack: Postgres is a great pub/sub and job server
#27Earlier quoted context omitted.
The pattern I follow is that workers immediately poll once when they start - this means that when your workers restart after crashing, they'll pick up any missing jobs.
I'm not seeing how this recovers from the failure scenario where a worker grabbed an event and then immediately crashed.
Typically you would implement visibility timeouts and other such stuff. Depending on the use case you could make specific optimizations or keep it generic and have SQS like semantics or something.
Re: System design hack: Postgres is a great pub/sub and job server
#28I.e. is this good advice because Postgres in particular is a great implementation of sql, or because sql in general is good enough to solve this problem, or a mix of the two?
Re: System design hack: Postgres is a great pub/sub and job server
#29Earlier quoted context omitted.
Yeah, but even without tuning, you can have hundreds of "sparse" queues with this pattern - you don't have to care about the frequency of insertions or deletions or the size of the rows.
I mean I agree I think with what I think you’re saying: as much as I love Postgres and SQL I’d much rather use Redis for this.
1.) *They want to transactionally commit work along with the change that caused it
2.) They are already using Postgresql not using Redis
3.) Requiring users install yet another service(Redis) just for this one item isn't worth the costs
Re: System design hack: Postgres is a great pub/sub and job server
#30I'm curious if the same holds true if you drop in Sqlite/MS Sql Server/Mysql. I.e. is this good advice because Postgres in particular is a great implementation of sql, or because sql in general is good enough to solve this problem, or a mix of the two?
- has strong performance vs, say, sqlite
- has "channel" and "trigger" support so you can avoid polling (which either slows down your jobs or limits your number of workers)
- is actually OSS (versus, say, mysql)