News for hackers. Stuff that matters.
Re:Do you really need Redis? How to get away with just Postg... by gunnarmorling on Saturday June 12, 2021 @04:52AM (#27482870)
The other issue with LISTEN/NOTIFY is that a client will miss any notifications sent while it is not running (e.g. due to crash, update, etc.). An alternative would be logical replication and change data capture (CDC), as provided for Postgres by Debezium for instance. That way, any consumers won't miss events during downtimes, as they'll continue to read from the replication slot from the last offset they had processed.

Disclaimer: I work on Debezium

Re:Do you really need Redis? How to get away with just Postg... by hardwaresofton on Saturday June 12, 2021 @05:24AM (#27483025)
Could you explain a little more about this (Debezium is awesome btw)? So after creating the proper replication slots, you set up change data capture via Debezium, then you listen to the CDC stream from the original DB you are connected to, correct?

This sounds like it might be vulnerable to dead consumers causing WAL to pile up without the right settings/periodic checks.

Re:Do you really need Redis? How to get away with just Postg... by gunnarmorling on Saturday June 12, 2021 @01:24PM (#27485951)
> then you listen to the CDC stream from the original DB you are connected to, correct?

Yes, exactly.

> This sounds like it might be vulnerable to dead consumers causing WAL to pile up without the right settings/periodic checks.

There are some subtleties around this indeed. You should monitor backlog of replication slots, so to identify inactive consumers as you say. Also, there are some corner cases you need to take care of: when listening to changes from a low-traffic database on the same PG host that also has a high-traffic database, the replication slot may not be acknowledged often enough. Debezium mitigates this by optionally writing changes to a dummy heartbeat table in the low-traffic database, so to advance the replication slot.

In Postgres 13 there's also a new option "max_slot_wal_keep_size" which limits WAL size retained by a replication slot. This prevents unbounded WAL growth, at the risk of consumers to miss events if they are down for too long.

All in all, proper monitoring and alerting is key.

Re:Do you really need Redis? How to get away with just Postg... by jbverschoor on Saturday June 12, 2021 @05:52AM (#27483160)
This is by design and very common with pub/sub.
Re:Do you really need Redis? How to get away with just Postg... by supermatt on Saturday June 12, 2021 @05:10AM (#27482960)
isnt this also the case for redis pubsub?
Re:Do you really need Redis? How to get away with just Postg... by Nick-Craver on Saturday June 12, 2021 @09:08AM (#27484221)
For pub/sub yes that's correct. For full info though: Redis later added streams (in 5.x) for the don't-wan't-to-miss case: https://redis.io/topics/streams-intro
Re:Do you really need Redis? How to get away with just Postg... by philjohn on Saturday June 12, 2021 @05:26AM (#27483040)
I'd need to check, but I think so.

Which is probably why if you don't want loss if consumers go down a proper queue system (RabbitMQ, ActiveMQ, Amazon SQS, Kafka if you don't care about ordering between partitions) is the way I'd go.

Re:Do you really need Redis? How to get away with just Postg... by MichaelMoser123 on Saturday June 12, 2021 @01:13PM (#27485868)
then what's the point of this feature as part of the db, if it doesn't do persistance?
Re:Do you really need Redis? How to get away with just Postg... by BiteCode_dev on Saturday June 12, 2021 @06:29AM (#27483387)
Then use streams.