👨‍💻 Joe thread👨‍💻 Joe thread
CaseOh the the biggest OFCCaseOh the the biggest OFC
Back to blogs

Caseoh is the biggest

Oct 25, 2024 • 1 min read

I was reading HackerNews a few months ago and came across this post. It demystified something I’d long wondered about but hadn’t investigated myself: PubSub with PostgreSQL. Most PubSub implementations I’ve seen rely on some sort of message broker like Redis. To be fair, the Redis PubSub interface is pretty easy to work with (I think I have a post or two showing just how easy), and if you were purely working in memory, it would be totally fine. However, most applications rely on some sort of SQL database. In that case, in order to “publish”, you have to write to the database and then notify listeners over your message broker. You end up having to maintain two systems and it’s kind of annoying.

If you’re using MySQL or Sqlite, then you’re pretty much stuck. However, Postgres is a true modern marvel and once again has its own solution called Listen/Notify. This post is going to show you how to use Listen/Notify in your Golang applications with pgx Conn.WaitForNotification:


© 2024 | Joe thread