Multi-tenancy

Learn about how to implement multi-tenant notifications in Novu

Multi-tenancy is a common use case for a lot of companies that have multiple organizations that use their applications. In some cases, there is a need to separate the behavior of the notification system depending on the individual tenants.

Tenants are also commonly called workspaces or organizations.

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 tenant identifier.

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 subscriberId={`${tenantId}:${userId}`} />;
}

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

Adjusting 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: "Acme Corp",
      logo: "https://acme-corp.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)

FAQ

On this page