Skip to content

Scale out

Gerasimos (Makis) Maropoulos edited this page Jul 14, 2019 · 2 revisions

Scale out through StackExchange interface and its completors is a feature that was implemented at neffos v0.0.6.

Made after a user feature request* with the five following commits:

  1. New feature: Scale-out using Redis built-in StackExchange implementation
  2. Add the ability to register and use more than one StackExchange
  3. Add nats StackExchange and scale-out example
  4. Add nats support for the new Server.Ask method
  5. Add redis support for the new Server.Ask method
  6. Export nats subject prefix

Scaling out a neffos app can be achieved by adding just three extra lines of code(!)

  1. Import github.com/kataras/neffos/stackexchange/redis or nats
  2. Initialize the StackExchange, e.g. exc := redis.NewStackExchange(...)
  3. Right after the server := neffos.New add server.UseStackExchange(exc).

Each StackExchange contains its own configuration.

How it works

  1. Each client connected to a neffos namespace is subscribed a channel/subject and unsubscribes itself on namespace disconnection.
  2. Each time a neffos Broadcast is called the message directly goes to the registered StackExchange.Publish method, which takes care to publish the message to the correct channel/subject, so subscribers can be notified about this message.
  3. Each time a subscriber notified for a new message its Conn.Write is responsible to dispatch that message to the client side.
  4. The same pattern is used for one to one messaging and Server.Ask.

Use this feature when you have multiple neffos servers hosted independently for a particular neffos app of yours and you want your app to be able to communicate with all of those neffos servers as one.

Next steps