2 apps connecting to the same backend (most likely there will be more than just one common backend in the future).
For simplicity let’s just consider having the app (that’s the frontend implementation) and the backend.
Establishing a connection and calling methods on the backend basically works. But I discovered the following issues.
Issue: Setting up the connection
When or where should the connection be set up? “Methods from a given client run one at a time” (see docs). If we connect to the backend on startup, we will use the same connection for every method call. This means that you should call
this.unblock() from within the backend method or otherwise it would dramatically slow down the whole app the more users are connected to it.
To work around this I’m thinking of setting up a connection per user some how. But I don’t know how. Or connect on each method call.
What would be best practice here? Or which implications does each approach have?
Issue: Calling a method
Let’s assume we handled the connection stuff. Now we call a method on the backend connection.
- How should the method be called? Sync or async?
- How (and maybe that’s the most important question) can we handle the case when we lost the connection to the backend? This might be a common scenario.
My current solution for 2) would be to check the connection status on each method call. If
Meteor.status().connected is equals
false then I just throw a new
Meteor.Error so the client could just tell the user to retry.
For some operations we might go with eventual consistency by waiting for the connection to reconnect. But that’s not the default case.