How to best structure pub/sub in my app


#1

Just calling out to the greater community here to see what you think is the best way to subscribe to data in my app I am building. Let me explain what the app does and how it works.

Very simple app for tracking the value of a users share portfolio.
Build using react for the UI.
Users build their portfolio by adding the actual trades they have made, the app does the rest.
There are a number of collections (not including the user and standard collections):

  • Update collection, which is like a news feed for the app.
  • Portfolio collection, users currently only have one, but in the future may have more.
  • Trade collection, these are all the trades linked to the users portfolio
  • Stock collection, this is a collection of all the stocks being tracked across the portfolios, it contains most recent share price etc…
  • Dividend collection, collection of all the dividend payments for all the tracked stocks

Originally I had it so that the main layout component triggers a subscription to the user portfolio and all their trades.
On the news page another subscription was kicked off for all the update feed.
On the portfolio information page another subscription was kicked off for all the stock and dividend information.
This means that changing pages meant waiting for subscriptions to sync.

I’ve since updated the app and now I make one subscription call to get all the information: Updates, Portfolio, Trades, Stock and Dividend information… This subscription runs once, and is only called again when the user updates their portfolio (needs to do this because the Stock and Dividend publication limits what it shares to only the relevant stocks from the users portfolio, so adding a new stock needs to update the subscription).

I have found this to make the app perform much better as all the information is at hand immediately without waiting for subscriptions. With the previous method, I watched my Kadia:Debug and it was constantly subscribing and dropping when changing pages. I know it means each subscription is pretty much completely custom, but that’s the nature of the app…

Are there any major downsides to doing this?
Does anyone have any other suggestions?


@arunoda - any thoughts on this? My decisions here are largely because of what I saw in Debug and Kadira UI.


More efficient to subscribe on a global level rather than in components?
#2

I’m not a performance expert, but I think the downside would be that the more data you subscribe from, the more load it puts on the server. So it’s usually recommended to only subscribe to data you actually need, rather than subscribe to every single publication right from the start.

To fix the subscription constantly dropping issue you can look into Subs Manager: https://github.com/kadirahq/subs-manager


#3

Yeah the way I understand it to work is the server holds it all in RAM so the more things concurrently subscribed to - the more RAM you’re eating server-side.

However given that my app is pretty much comprised of six different views, and the majority of the data is required for 80% of those views, I am pretty much always subscribing to the same data. The only difference is on a couple of those views I don’t need all of it.

I see what your saying though.
Install subs manager, and be very specific with the subscriptions on each view.
That should solve everything, and hopefully lead to a lower RAM consumption on the server, and should be a similar user experience…


#4

@cstrat I think you should use subs-manager as @sacha mentioned.

and the RAM usage of the server because of subs-manager is a non-issue most of the times.


#5

Yeah I will give it a try and report back :slight_smile:

Thanks


#6

Hello,

Is anybody using subManager with react in production and has anything to say about it ?

I think it is a great idea to use it, but it is strange as no one seems to talk about it ( Meteor’s guide, base, even Mantra is not using it ).

Thanks for your responses,