How to handle data flow

I’m curious on how to deal with data g=flow in Meteor applications, particularly when the internet connection drops. For example, if I click a button in my app. which adds a record to a collection, which in turn causes Meteor to add an item to alist in my app, is the flow as follows:

  • record gets added to local collection
  • record then gets added to remote collection
  • list in app. gets the new item

If it is, what happens if the internet connection drops before clicking the button? Does Meteor add it to the local collection anyway? Does it try to synch this to remote once the connection gets re-established?

The short version:

Yes and yes. :smile:

The long version:

Requests to the server will be queued until the connection comes back. However, I would be cautious about relying on the behaviour you may see on the client, especially if client actions are dependant upon the successful results of earlier, queued actions. What happens if you queued up some actions which cause unexpected results because the server overrules your client’s expectations when the connection returns? Remember, the server always wins, so you should code to expect the unexpected.

Refer to the documentation and handle connection issues gracefully.

Hmm, I wouldn’t want to ever really rely on a queing mechanism, so it looks as though I have to test the connection each time I want to call a server method (?)

If I wanted to queue them, could my application control this, ro does Meteor take over?

Don’t think your application can stick its finger in that side of Meteor’s logic. Out of pure interest, why is this behavior not acceptable for you?

By the sounds of it, if when calling a server method to add data to Mongo, the data gets automatically added to mini-Mongo, then gets propogated to the server when the connection comes back (which could be hours), I am visualizing a lack of control of the data and the effects on the UI.

Let me give an example: If I have a list of sortable items in my UI and when I re-sort them I need to send a request to Mongo to maintain a record of their sort order. If the data gets stored in mini-Mongo first, but the lack of internet connection does not propogate it to the server, then someone else in the world re-sorts the list, which does get saved to the server, what happens when my connection to the server is re-established…

  1. Meteor sends my local data to the server, overwriting the other persons sort order data?
  2. Meteor pulls from the server, overwriting my sort order data and changing the UI (which could cause a bad UI experience)?
  3. Something else?