←back to thread

570 points davidgu | 1 comments | | HN request time: 1.106s | source
Show context
hombre_fatal ◴[] No.44525152[source]
Interesting. What if you just execute `NOTIFY` in its own connection outside of / after the transaction?
replies(4): >>44525332 #>>44525408 #>>44526003 #>>44528534 #
parthdesai ◴[] No.44526003[source]
You lose transactional guarantees if you notify outside of the transaction though
replies(2): >>44526146 #>>44534706 #
hombre_fatal ◴[] No.44526146[source]
Yeah, but pub/sub systems already need to be robust to missed messages. And, sending the notify after the transaction succeeds usually accomplishes everything you really care about (no false positives).
replies(1): >>44526451 #
parthdesai ◴[] No.44526451[source]
What happens when transaction succeeds but the execution of NOTIFY fails if it's outside of transaction, in it's own separate connection?
replies(2): >>44526695 #>>44527506 #
saltcured ◴[] No.44526695[source]
For reliability, you can make the recipient poll the table(s) of record for relevant state and use the out-of-band notification channel as a latency-reducer. So, the poller is eventually consistent at some configured polling interval, but opportunistically can respond much sooner when told to check again ahead of the next scheduled poll time.

In my experience, this means you make sure the polling solution is complete and correct, and the notifier gets reduced to a wake-up signal. This signal doesn't even need to carry the actionable change content, if the poller can already pose efficient queries for whatever "new stuff" it needs.

This approach also allows the poller to keep its own persistent cursor state if there is some stateful sequence to how it consumes the DB content. It automatically resynchronizes and the notification channel does not need to be kept in lock-step with the consumption.

replies(2): >>44527174 #>>44528147 #
1. parthdesai ◴[] No.44527174[source]
fwiw - that's what Oban did for the most part. It sent a signal to a worker that there was a new job to pick up and work on. At scale, even that was an issue.