Advanced Concepts

Multi-tenancy

Learn how to implement multi-tenant notifications to support different organizations or workspaces within your application.

Multi-tenancy is a common use case for applications that serve multiple tenants which are also called organizations or workspaces. It lets you isolate notification behavior, content, and preferences for each tenant, ensuring your subscribers see only the notifications relevant to their organization.

Some of the common multi-tenancy use cases are:

  • Group subscribers notification feeds by the tenant
  • Adjust the content of the notification depending on the tenant

How to implement multi-tenancy in Novu

Novu supports multi-tenancy out of the box, the most simple way to implement tenant separation is by prefixing the subscriber identifier with the

const subscriberId = `${tenantId}:${userId}`;
 
await novu.trigger({
  workflowId,
  to: {
    subscriberId,
  },
  payload: {
    tenantId,
  },
});

Tenant in Inbox

When using the Inbox feature, you can use the tenant identifier to group notifications by tenant.

import { Inbox } from "@novu/react";
 
function InboxComponent({ tenantId, userId }) {
  return <Inbox subscriber={`${tenantId}:${userId}`} />;
}

Each subscriber in a tenant will have it's own unique inbox feed, including a separate preference configuration set.

Customize notification content based on tenant

When triggering a notification, you can pass a custom tenant object or identifier and use it to manipulate workflows or content.

const subscriberId = `${tenantId}:${userId}`;
 
await novu.trigger({
  workflowId,
  to: {
    subscriberId,
  },
  payload: {
    tenant: {
      id: tenantId,
      name: "Airbnb",
      logo: "https://airbnb.com/logo.png",
      primaryColor: "red",
    }
  },
});

The tenant object will be available to use in the workflow editor as a variable for the following areas:

  • Content (use {{payload.tenant.name}} to display the tenant name in an email or any other channel)
  • Step Conditions (use {{payload.tenant.id}} to conditionally execute a step based on the tenant)
  • Use the Inbox data object to filter notifications by tenant.

To group subscribers in a group, use Topics.

Frequently asked questions

The following are the frequently asked questions about multi-tenancy in Novu.

On this page

Edit this page on GitHub