Subscription performance (1 vs many)

Hi everyone!

I have done some searching on this I seem to find conflicting information, so hopefully we can have a solid answer here.

When planning how to set up collections, what is better from a performance standpoint? Splitting up into a higher number of collections (With the consequent higher number of subscriptions) or use the power of Mongo document polymorphism and reduce the number of subscriptions by bunching similar documents together?

To put it into perspective, I’m planning a kind of logging application to log all kinds of different events. My dilemma is as follows.

All the events have a time, a comment, a createdAt and a createdBy field in common. Apart from that, each type of event has a variety of extra fields, so the documents are similar but not overly so (If that makes sense).

So I’m wondering wether to create a collection and subscription for each type of to pull them in together with one subscription.

So the bottom line I guess is: Does having a high number of subscriptions have an impact on performance on the client or on the server?

Thanks :slight_smile:

1 Like

This is a very subjective question. Deciding between these two is very subjective. But keeping a subscription open for a long time does not affect the performance in general.

So, what you should try to do it reduce the number of document you are fetching to Meteor. You can optimize it with what we called Observer Reuse. See:

So, I suggest you to start with the easiest way to implement your subscriptions. Then monitor them and optimize as you need.

1 Like

Thanks Arunoda.

The number of documents I’m fetching at any given time is relatively small. Basically the entries for any particular day, max about 150 or so. The thing is within those ~150 documents there might be about 8 or 9 different types of documents that only share the fields I mentioned.

My gut instinct is that with that amount of documents being fetched (Subscriptions are at template, or should I say React component level) it’s probably easier from an organisational point of view to have multiple indexed collections.

I wanted to get the thoughts of wiser people than me, so thanks for that :smile: