πŸš€ Meteor Scaling/Performance Best Practices

Use as many re-usable publications as you can […]

Go one step further - split mixed ones into shared and non-shared. Let’s say your publication looks like this:

Meteor.publish('notificationsForUser', userId => {
  // Authorization...
  return Notifications.find({
    $or: [{ type: 'global' }, { type: 'user', userId }]
  });
});

Then check if the number of shared documents (here: type: 'global') is large. If so, such a split:

Meteor.publish('notificationsGlobal', () => {
  // Authorization...
  return Notifications.find({ type: 'global' });
});

Meteor.publish('notificationsForUser', userId => {
  // Authorization...
  return Notifications.find({ type: 'user', userId });
});

May drastically increase the number of reused observers and, in the end, greatly reduce both DB and server pressure. Once I’ve split such a publication into 4 (mixed ~> global, organisation, month, user) and reduced costs by 30% (we switched to a smaller DB instance and reduced the number of containers).

Just remember - always measure it for yourself!

14 Likes