You can spew messages into sqs then have a lambda on sqs sending to pg. Funny, we were going to use kafka too, but just sending to mysql worked just fine . One day that will change, obviously.
It works fine on the happy path, but if mysql goes down, you lose things. Having a distributed, resilient queue has availability benefits.
Postgres: A better message queue than Kafka?
31–40 of 47 posts
Re: Postgres: A better message queue than Kafka?
#32You can spew messages into sqs then have a lambda on sqs sending to pg. Funny, we were going to use kafka too, but just sending to mysql worked just fine . One day that will change, obviously.
It works fine on the happy path, but if mysql goes down, you lose things. Having a distributed, resilient queue has availability benefits.
Re: Postgres: A better message queue than Kafka?
#33I don’t think this article made a compelling reason not to use Kafka. In fact it may have made the opposite point. Wouldn’t it have been easier to just use Kafka?
Re: Postgres: A better message queue than Kafka?
#34Not just Postgres. You can do exactly this with MySQL and SQL server too because they both support SKIP LOCKED. Interestingly, the plain old file system on Linux also makes the basis of a perfectly acceptable message queue for many use cases - the thing that makes it work is that the file move operation is atomic. Atomic moves are what make queuing systems possible. You could write a file system based message queue i…
What makes it atomic is running publishers and consumers on the same box (since you're sharing filesystem between those). Also listdir is a big bottleneck here: while True: # get files in outbox files_in_outbox = [f'{PREFIX}/outbox/{x}' for x in os.listdir(f'{PREFIX}/outbox')]
It's the move/rename that is atomic.
Re: Postgres: A better message queue than Kafka?
#35Earlier quoted context omitted.
What makes it atomic is running publishers and consumers on the same box (since you're sharing filesystem between those). Also listdir is a big bottleneck here: while True: # get files in outbox files_in_outbox = [f'{PREFIX}/outbox/{x}' for x in os.listdir(f'{PREFIX}/outbox')]
>> What makes it atomic is running publishers and consumers on the same box (since you're sharing filesystem between those). It's the move/rename that is atomic. https://man7.org/linux/man-pages/man2/rename.2.html
However, there will
probably be a window in which both oldpath and newpath refer to
the file being renamed.
But that's not even the main point.1. Move happens after email is sent, so there is a window where email is already being sent but file still exists. 2. Even if you do it before, there's still a window between os.listdir() and os.remove() 3. Complexity is O(N^2) due to listdir() + getctime() being called on every iteration.
If you just want to ensure order, it probably works fine at a small scale. But it would be unwise to run multiple consumers on a single instance, and impossible to run them on multiple instances.
Re: Postgres: A better message queue than Kafka?
#36Earlier quoted context omitted.
It works fine on the happy path, but if mysql goes down, you lose things. Having a distributed, resilient queue has availability benefits.
> It works fine on the happy path, but if mysql goes down, you lose things. Why do you have to lose things if the DB goes down? Agreed, untuned & unconfigured MySQL (and MongoDB) out-of-the-box can lose things due to bugs and design issues, but that is the case even when they are running. However, DBs, in general are made precisely for the purpose of safely storing things and not losing them. OTOH, the number of Kafk…
Was the data actually acked across all replicas by Kafka? If so, very interested in how it was lost.
Re: Postgres: A better message queue than Kafka?
#37"We didn't actually evaluate Kafka for this use case, because we know Postgres, so we used that."
Weird article angle.
Re: Postgres: A better message queue than Kafka?
#38A controversial, but a very pragmatic take. Queues are great for semi-infinite scalability, but you rarely need it. There's numerous subtle benefits to using db compared to regular message queues that are often overlooked. Being able to delete, reorder, or edit specific messages can be a lifesaver when things go wrong. Most common issue with queue-based systems is getting overwhelmed with messages. Either your consum…
Here's just a few examples from my experience: 1. Huge number of messages from test system were accidentally inserted into production. Queue solution: disable consumers, move messages to a temporary queue while filtering them, move messages back to the old queue, enable consumers DB solution: just delete rogue messages 2. We want to store some of the messages, but we're not ready to process them yet Queue solution: c…
2. Kafka - do what you did with your DB consumers.
3. Kafka - consumers going down can't cause duplicates, what's even going on with your queue?