Making multiple Meteor method calls vs. doing all computation in one method


#1

Basically, I am calling an external API multiple times to get information that is necessary for my application to work.

When a user submits a form, there is a loading screen. Calling Meteor methods multiple times from the client allows me to update the user what step the process is on after each method is called. The API calls will also be split up and not be called all at once vs. just using one method call.

So with that being said, is it better, performance wise, to make multiple API calls from one large method or is it better to call multiple meteor methods from my React component with each method doing once piece of the puzzle. There is a huge UI benefit (for my app) when calling methods multiple times, but what about performance?


#2

One roundtrip is better than multiple roundtrips for a client. On the server side, if your methods are doing expensive computation, that’s something you might want to avoid. But network calls are non-blocking, so if you call this.unblock() in your method before the network call, you should not see a performance hit.

If you need the progress status, that is not something you can do without multiple method calls, so if that’s working for you and gives a good UX for your users, go for it!


#3

Be careful when using this.unblock - it may not do what you think it does. In fact, in most use cases it makes no difference at all to performance and in a few situations, it may actually break your application! I take a closer look at it in this article, if you’re interested.