About scaling

This section will explain what kind of server configuration you should use, based on the actual operation image.

system-overall-view.png

The Master/Slave feature of obniz-app-sdk makes it easy to scale the system.

The Master allocates obniz to each Slave, and the Slaves make a connection with the allocated obniz device.

system-scalling.png

The Master and Slave communicate via Redis (PubSub), which allows for easy redundancy.

⚠Master does not support redundancy. Only Slave and Redis can be redundant.

Example of scaling using obniz-app-sdk

As mentioned above, Redis is required for scaling.

Redis is generally used as an in-memory database, but obniz-app-sdk uses it as PubSub.

On Ubuntu, you can install it with the following command.

$ sudo apt install redis-server

Once the Redis setup is complete, add the obniz-app-sdk option to use Redis.

If you installed it locally, write as follows.

const app = new App({
  appToken: "<<< Here is the token >>>",
  workerClass: MyWorker,
  instanceType: AppInstanceType.Master, // AppInstanceType.Slave for Slave
  ObnizClass: Obniz,
  Database: "redis", // added
  databaseConfig: "redis://address:6379", // added
})

app.start();

Now, load balancing is enabled.

If you start one Master and multiple Slaves in this state and install applications on obniz, the load will be balanced automatically. Also, when you close a Slave, the portion allocated to that Slave will be taken over by the other Slaves.

⚠When you add more Slaves, the load will not be automatically taken over to the new Slaves. If you install the app to the new device, it will be allocated to the new Slaves.

You can store data from Slave via database or Redis, and refer to it from other services.

There are also other ways to send the data directly to other services or to integrate it directly into Master.

system-linking-services.png

Since obniz-app-sdk is a library, you can directly integrate it into existing services.