Repository navigation
Add Notifier, implemented for PostgreSQL with LISTEN/NOTIFY - #77
Merged
Merged
Conversation
A relay running as several processes on one database has no way to push an event accepted by one process to the subscribers of the others. Notifier is an optional interface for stores that can propagate events between such processes: Notify is called by the relay for every accepted event and Notifications delivers what every process notified. PostgresBackend implements it with pg_notify on a configurable channel. Events that fit in a pg_notify payload travel inline; bigger ones are announced by id and read back from the table by the receiver, so only ephemeral events above the limit are lost.
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A relay running as several processes on one database (e.g. behind a load balancer) has no way to push an event accepted by one process to the clients subscribed on the others: live subscriptions live in each process's memory.
fiatjaf/relayer#167 added a
Notifierinterface on the relayer side and resolves it on theRelayfirst and on theStoresecond. This PR adds the store side, so a backend with native change notifications can provide it out of the box.Change
Optional, like
Counter. The relay callsNotifyfor every accepted event after saving it (ephemeral ones included, since they are never saved);Notificationsmust deliver everything any process notified, including the caller's own, and keep the channel open untilctxis done.PostgresBackendimplements it withpg_notify/LISTENviapq.NewListener(which reconnects by itself):NotifyChannelfield, defaults tonostr_eventspg_notifypayload (8000 bytes) travel inline; bigger ones are announced by id and read back from the table by the receiver, so only ephemeral events above the limit are lostNotificationsneedsDatabaseURLsinceLISTENtakes over a dedicated connectionTests
test/notify_test.goruns two backends on one embedded postgres and checks that a small event, an over-limit event (with full content read back) and an ephemeral event notified through one arrive on both, and that cancelling the context closes the channels.Once released, relayer can switch to
type Notifier = eventstore.Notifier.