Add a guide to the documentation on using the library with multiple server instances.
This seems to be a fairly common query from users trying to architect their application with server redundancy in mind (1, 2, 3, 4).
In general, the most scalable approach is to use some external pub-sub or message broker solution (Eg, Redis, RabbitMQ, NATS, etc.) and for each subscription to a topic you create a dedicated channel.
Then, when you receive an incoming request, simply register its session to the corresponding channel that the user is requesting to be subscribed to.
Now, when you want to broadcast messages, instead of calling Channel#broadcast you instead publish a message to the messaging service directly, triggering all of your subscribed channels to rebroadcast the event across all server instances.
An example flow would be the following:
- Server boots and connects to Redis.
- Server subscribes to the
stock-updates topic and creates and stores a new channel associated with the name stock-updates.
- Client makes a request to
GET /subscribe?name=stock-updates.
- Server checks that a channel exists with the name
stock-updates, then creates a session and registers it to the channel.
- Some service (maybe the Server itself) publishes to the
stock-updates Redis topic.
- Server receives the event from Redis and calls the
broadcast method on the channel associated with stock-updates.
- Client receives the broadcasted event.
The documentation should include sample code for a few of the most popular pub-sub and/or message broker technologies.
See this comment for more details.
Add a guide to the documentation on using the library with multiple server instances.
This seems to be a fairly common query from users trying to architect their application with server redundancy in mind (1, 2, 3, 4).
In general, the most scalable approach is to use some external pub-sub or message broker solution (Eg, Redis, RabbitMQ, NATS, etc.) and for each subscription to a topic you create a dedicated channel.
Then, when you receive an incoming request, simply register its session to the corresponding channel that the user is requesting to be subscribed to.
Now, when you want to broadcast messages, instead of calling
Channel#broadcastyou instead publish a message to the messaging service directly, triggering all of your subscribed channels to rebroadcast the event across all server instances.An example flow would be the following:
stock-updatestopic and creates and stores a new channel associated with the namestock-updates.GET /subscribe?name=stock-updates.stock-updates, then creates a session and registers it to the channel.stock-updatesRedis topic.broadcastmethod on the channel associated withstock-updates.The documentation should include sample code for a few of the most popular pub-sub and/or message broker technologies.
See this comment for more details.