Baking Multi Tenancy in SaaS
Courtesy ClipArtMax

Baking Multi Tenancy in SaaS

Multi-tenancy is a common requirement in any modern SaaS. The way a B2C SaaS will support it will vary greatly from a B2B SaaS. Also its implementation would vary greatly from use case to use case. A good architect would anyway define multi-tenancy support and the level of separation of concerns per tenant in the architecture right from the beginning. Building multi-tenancy later or as an after-thought is a recipe for unwarranted complications.

Multi-tenant Schema Options

No alt text provided for this image


A. Database per Tenant

B. Schema per Tenant

C. Records per Tenant

Other factors affecting multi-tenancy

  • Authentication Methods
  • Authorization Methods
  • Security and Data Isolation requirements for each tenant.
  • Load Balancing/Geo-Graphical distribution/Tenant Partitioning.

Security and Isolation requirements can demand a tenant's data be on completely separate databases or disks or may be across different instances or clouds. Sometimes it may require encryption of data using separate tenant keys. Tenant partitioning is another way of load balancing of geographically co-locating tenant database closer to them. Many reverse proxy server/gateways/routers to route API calls for a tenant to a particular geographically co-located microservice instance running nearby. There are myriad of ways you could partition this to achieve various architectural goals.

If you are using Spring Boot it provides a very excellent way to implement multi-tenant microservices in your SaaS by way of AbstractRoutingDataSource class. All your database queries can be routed to a data source pointed to by each tenant.

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource



public class MultiTenantRoutingDataSource extends AbstractRoutingDataSource {
?
 ? @Override
? ? protected Object determineCurrentLookupKey() {

? ? ? ? return TenantContext.getTenant();
? ? ? ?
? ? }
};        

Another example of how Multi-Tenancy can be baked in a Spring Boot based Microservice.


Ankit Pawale

?? Software Engineer at - Global Payments Inc. | ? Java | ?? Spring Boot | ?? JavaScript | GCP | ?? Cloud-Native Applications | Payment Gateways

3 年

Thanks for sharing this article Bhavik Shah .

要查看或添加评论,请登录

Bhavik Shah的更多文章

  • Scaling up with AWS Lambda

    Scaling up with AWS Lambda

    AWS Lambda is a very effective deployment model for various web frameworks like NodeJS Express, Python FastAPI, GoLang…

  • Composable Architectures

    Composable Architectures

    What is CA? Composable architecture is a way of designing software that makes it easy to create reusable components…

  • Go Lang Framework to watch in 2022

    Go Lang Framework to watch in 2022

    Go Lang is becoming quite popular not only because it is easy to learn but also for its performance, concurrency and…

  • Python frameworks to watch in 2022

    Python frameworks to watch in 2022

    There have been many popular python frameworks. Flask and Django being the most popular of the lot.

  • Why Vue is preferable to Angular in 2022?

    Why Vue is preferable to Angular in 2022?

    UI frameworks have come of age. We had used Angular 1.

  • How to migrate legacy applications to newer architectures

    How to migrate legacy applications to newer architectures

    This is a well known challenge, faced by many organizations atleast once during the software lifecycle. It is faced by…

  • Eazy Kubernetes on Google Cloud

    Eazy Kubernetes on Google Cloud

    Google Cloud makes is super easy to deploy kubernetes clusters. Step 1: Choose to create a cluster Step 2: Provide…

  • Website to App in Minutes!

    Website to App in Minutes!

    Convert website into mobile app! It has been said that an average user spends over 2 hours on mobile phone while 86% of…

    6 条评论
  • How to choose a NoSQL Database

    How to choose a NoSQL Database

    NoSQL has been beautifully explained by Martin Fowler in his book especially the four main types of NoSQL databases…

  • Serve Windows from Google Cloud

    Serve Windows from Google Cloud

    Google Cloud Platform has come a long way from AppEngine days when it was more of PaaS platform allowing you to run app…

社区洞察

其他会员也浏览了