js-data-examples icon indicating copy to clipboard operation
js-data-examples copied to clipboard

RethinkDB example not suitable for a multi-node cluster

Open analytik opened this issue 9 years ago • 2 comments

Hi,

First of all, thanks for the sample! It's helping me to kickstart a project. However, if someone would run more than one replica of the socket.io server, horrible things would start happening, as instead of using a RethinkDB changefeed - which is one of the main reasons why people use RethinkDB in the first place - it just emits a message with changes which the specific server received. For example,

  • user 1 is connected with socket.io to server 1
  • user 2 posts data which get load balanced to server 2
  • server 2 saves data and emits a socket.io message
  • user 1 receives nothing

So all calls like messageService.sendCreateMessage('post', post); should be removed, and socket.io connection needs to be replaced with something like

function on_user_connected( ... ) {
    r.table("posts").changes().run(rConnection).then(function(cursor) {
        cursor.each(function (err, item) {
            ioServer.emit('post created or deleted or updated', JSON.stringify(item, null, 2));
        }
    };
}

I haven't worked up a specific solution yet, but I might post a more specific sample later.

analytik avatar Sep 03 '15 12:09 analytik

I'm looking forward to your pull request :)

jmdobry avatar Sep 03 '15 15:09 jmdobry

Heh. I'll see what I can do, I just wanted to make sure I'm not misunderstanding something about the application's design, as I'm new to Express. :)

analytik avatar Sep 03 '15 17:09 analytik