How do I achieve clustering and load balancing with Node-red native capabilities

If the N node-red instances are each running on its own server (e.g. s1, s2, and s3) using the standard port # (i.e. 1880), the the load balancing can be defined by adding the same DNS hostname for all three servers. Individual requests will randomly end up at one of the three endpoints if DNS is configured properly.

If the N node-red instances are all running on the same server, each instance will need to be configured with its own port # (e.g. 18801, 18802, and 18803) -- then you can set up a simple nginx reverse proxy listening on the original port #1880, forwarding traffic to one of the three instances, using a configuration similar to this:

server {

  listen 1880;
  server_name nodered.example.com;

  location / {
    proxy_pass  http://nr-cluster;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

}

upstream nr-cluster {
   server nr1.example.com: 18801;
   server nr2.example.com: 18802;
   server nr3.example.com: 18803 down;
}

... unless I misunderstood your question, and you really want to pass msg objects from one instance's flow to the next -- in which case MQTT pub/sub will probably do what you need.

1 Like