Back to projects
Aug 31, 2024

Multi-Tenant Architecture

Best solution to manage application version for huge client number

Background

Imagine that we had 100 total clients and 10 application portals. We did a hotfix and wanted to apply this change to all client. How would we proceed? We updated all application to the newest version one by one. Imagine that one portal took varying amounts of build time, ranging from 30 seconds until the longest one was 20 minutes. How long would it take for one update? To solve this issue we decided to implement multi-tenant architecture, which we called it multisite.

Definition

What is Multi-tenant architecture? Cited from Multi-Tenant Architecture: What You Need To Know “Multi-tenant architecture is a design approach that enables multiple user groups — referred to as tenants — access to one instance of an application or system. This is much like an apartment building, where various tenants have their own apartments.”. This architecture helped us to easily update application for all clients.

Implementation

  1. Backend Part Backend would receive application URI served by frontend and return some data such as college id, college name, etc. We managed the colleges’ configurations in a console application which can be accessed by Our employees with a VPN.

  2. Frontend Part After received the configurations, frontend would save the configuration in cookie or localstorage. The configuration would be sent within request header if user was not authenticated.

Obstacles

Multi-tenant was a new architecture We implemented. So there were some problems We faced on:

  • Data Inconsistency As far as I knew, this issue occured because the application used same database connection.

  • Implementation with SSR Mode To retrieve the site configurations, the frontend only need to send application URI to the backend. But there was a different behavior between localhost and staging server. On localhost, we could easily obtain the hostname, but on the staging server, we could not obtain the hostname because the frontend application runs behind NGINX, which cause the frontend application only receive “localhost” as the hostname. To handle this, we should manually add Host header in the NGINX configuration.