Skip to content
ismaeil-shajar edited this page Nov 16, 2021 · 2 revisions

Overview

In Saas applications; multitenancy is a mode of operation where multiple independent instances share the same environment. In plain English, it is when multiple tenants and businesses use the same Saas application.

Multitenancy Archituecture

I will not cover how to design a multitenancy application in this article, however, you can read about it in detail here: What is Multi-Tenant Architecture? By Andy Patrizio

From here on, we are going to work on an example about the multi-tenants using multiple Databases and microservices architecture.

What are we going to build?

We will focus on ROLE-BASED ACCESS CONTROL with multi-database and will use two databases -MySQL and MongoDB- for each tenant: Image description We will use sample web services to test the flow, for example creating users, sending and receiving notifications... etc.

Nest.js

From nest js: nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript), and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).

Installation

You will need to install Node.js, and it must be version 10.13 or higher. I will install v12 LTS and npm. I recommend that you use nvm to install node.js

Setup

You need to install nest cli using npm:

npm install -g @nestjs/cli

then create a new nest.js project:

nest new multi_tenant 

If you encountered an error during the installation like:

npm ERR! invalid json response body at https://registry.npmjs.org/ajv reason: Unexpected end of JSON input.

You can use this to fix it:

npm cache clean --force