Subscriptions: One giant Monolithic or multiple small? which is preferred?

Which one is better?

  • subscribe to “all” data in the parent template and pass-on filtered portions of it to child templates, or
  • alternately, let each child template have its own small pieces of subscriptions

For example,

Templates.Parent.onCreated({
   this.subscribe("alldata");  
}) 

Templates.["Child"].onCreated({
   this.subscribe("alldata", only_for_my_id);
});

Suppose this Child template is a list item, and say, I have 1000 such list-items inside the parent, each with its own subscription - can Meteor/Mongo handle that??

1 Like

First read this: https://kadira.io/academy/improve-cpu-and-network-usage/

I can not assure you that have 1000 subscriptions is right, but you can post a list with his items in one publication and not have to worry about that

@KrishnaPG I guess you are referring to Best practice for drilling into more detail on a single record and pulling more fields from the database?

If you are displaying only some data on the parent template and need the detail data when parent containers are clicked, then separating the detail subscription is wise.

But if you are creating a parent template that consists of childs and each child is to display the whole data the first time, than creating the monolithic subscription from the parent is a better choice.

If all the info is presented on the same page then it doesn’t really matter.

If the UI has tabs and navigation controls then I strongly recommend using a big subscription. Going a-la-carte seems like a good idea at first but you end up with a laggy user experience later. Every time the user moves to another tab your app has to go to the server to fetch the data.

What I do is subscribe to the minimum data needed on the parent template and then subscribe to the rest when the first batch is ready.

4 Likes