I’ve x-posted to Reddit, and there’s been some good discussion. Since I originally posted, I had re-considered my architecture. Ultimately, having client-specific builds seems to carry more baggage then benefit. With pure multitenancy, release management is simpler and architecturally far more cost efficient.
So we’ve had to make a couple changes to support multiple tenants with a shared database and application instance. There have been two key pieces for my multitenancy implementation:
-
The definition of a
Tenantcollection to store tenant-specific metadata (with each associated collection storing atenantId), and -
Publication overloading (e.g., putting dynamic content in the publication name) based off of the
tenantId.
var tenants = Tenants.find();
tenants.observeChanges({
added: function (tenantId, tenant) {
Meteor.publish("someOtherCollection-" + tenantId, function () {
return SomeOtherCollection.find({tenantId: tenantId});
});
}
});
This is much different from:
Meteor.publish("someOtherCollection", function (tenantId) {
return SomeOtherCollection.find({tenantId: tenantId});
});
Because you won’t be able to simultaneously view two tenant instances. Your subscriptions will collide and things will get weird.