Skip to content

Add a guide for usage with multiple server instances #89

Description

@MatthewWid

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:

  1. Server boots and connects to Redis.
  2. Server subscribes to the stock-updates topic and creates and stores a new channel associated with the name stock-updates.
  3. Client makes a request to GET /subscribe?name=stock-updates.
  4. Server checks that a channel exists with the name stock-updates, then creates a session and registers it to the channel.
  5. Some service (maybe the Server itself) publishes to the stock-updates Redis topic.
  6. Server receives the event from Redis and calls the broadcast method on the channel associated with stock-updates.
  7. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions