1

I am working on a web application (the back-end is written in Node.js with a mongo-db), where the user can make, document and describe decisions. I am representing this in a tree structure as follows

{ 
  tree: {
    root: Node,
    nodes: [{   // keeping a reference to all nodes of the tree
      index: Number,
      node: Node
    }],
    lastIndex: Number
  }
}

Where Node is

{
  parent: Node,
  children: [Node],
  data: {
    d1: String,
    d2: [String],
    d3: Number,
    d4: Boolean
    // more data fields as above, probably not more than 10-20 fields per node
  },
  index: Number   // this node's index in the tree's node map
}

On the web application (i.e. in the browser), the user can perform the following actions:

  • Create a new tree
  • Add a node to a tree
  • Edit the data of a node
  • Delete a complete subtree
  • Change the order of the children of a node
  • Load a complete tree

The main action will be, to add new nodes and to describe them (fill the data fields). This can be done via mouse input mostly, so if the user is clicking quickly, he can create up to 5-10 nodes per second.

I want to send these modifications in real-time to the server and store them in the database (mongo-db). (Also I'm thinking about showing feedback on the page, that the current state is saved on the server, but I think this will come at a later point).

So it comes down to these requirements:

  • Most of the time I will be dealing with create- and update-actions on the nodes table (possibly many creates/updates per user per second).
  • There won't be much data sent from server to client (except when a new tree is loaded).

So, in my case, is it better to use REST calls or a websocket connection?

All help is really appreciated!

ForceOfWill
  • 435
  • 1
  • 6
  • 13
  • Maybe it comes down to whether you want completely asynchronous comms between client and server, which web sockets will give you, but you do need to add a websocket server. –  Oct 03 '16 at 17:31
  • @Berniev How is websockets different asynchronous from ajax? What would be the benefits in my scenario? And isn't the websocket server just another route I declare in node.js? – ForceOfWill Oct 04 '16 at 06:16
  • 1
    With websockets either client or server can send at any time –  Oct 04 '16 at 19:41
  • I only need the client to be sending data, so there is no benefit in switching to websockets? Isn't it faster? There can be multiple posts/updates per from the same user on the same tree per second. – ForceOfWill Oct 05 '16 at 06:20

0 Answers0