Repository navigation
Add Notifier for running several instances on one storage - #167
Merged
Merged
Conversation
Live subscriptions are tracked in memory, so an event published to one relay process was only pushed to the clients of that process. Notifier propagates accepted events between instances sharing a storage: Notify is called for every accepted event (ephemeral ones included) and Notifications delivers the events accepted by any instance. When a Notifier is present, AddEvent hands events over to Notify and delivery to local subscribers happens only through Notifications, so there is a single path and no duplicates. It is looked up on the Relay first and on the Store second, so a backend with native change notifications can provide one while any other backend can be combined with a transport of the user's choice. Add an example running several processes on one SQLite file, kept in sync over Redis pub/sub.
This was referenced Sep 14, 2026
Merged
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
Live subscriptions are tracked in memory (
Server.listeners), so when several relay processes share one database, an event published to instance a is only pushed to the clients connected to a. Clients subscribed on b or c never see it until they open a newREQ.Change
Adds an optional
Notifierinterface:Notifyis called byAddEventfor every accepted event, after it has been saved. Ephemeral events are passed too, since they are never saved and would otherwise be invisible to a storage-level implementation.Notificationsis subscribed byNewServer; whatever arrives is delivered through the usualnotifyListeners, so REQ filters apply as before.Notifieris present,AddEventno longer callsnotifyListenersdirectly. Events reach local subscribers only throughNotifications, giving a single delivery path with no duplicates.Relayfirst, then on theeventstore.Store, so a backend with native change notifications (e.g. PostgreSQLLISTEN/NOTIFY) can provide one later, while any backend can be combined with a transport of the user's choice today.Notificationsfails,NewServerreturns the error; the subscription context is cancelled onShutdown.Relays that don't implement
Notifierbehave exactly as before.Injectoris untouched.Example
examples/multi-instanceruns several processes on one SQLite file (WAL mode), kept in sync over Redis pub/sub. Addsgithub.com/redis/go-redis/v9to the module for the example.Tests
notifier_test.gowires two servers to one store through an in-memory bus and checks that an event published to one is delivered to subscribers on both, exactly once each; that a store-levelNotifierworks; that ephemeral events are notified; and that a failingNotificationsfailsNewServer.Also verified end to end with the example: two processes + Redis,
nak eventto one,nak req --streamon the other receives it.