In Cloud


The world of product development has evolved much in past few years. The new era has begun where the customers need not worry about the expensive servers,  software licenses,  maintenance , data loss etc.,

SaaS (Software as a Service) is a new form of business where customer pays for what he uses. The hardware & software licenses are maintained by the SaaS providers. All that the end user need is a device (PC or Laptop or mobile devices) with basic applications like browser and most importantly Internet connection.

Multi-Tenancy

This is an architecture where the software application deployed in a server shall serve multiple similar clients across the world. We shall call them tenants of our application (if multi-tenancy is enabled) . Since it is a technical blog let me jump straight into database modelling.

Achieving multi-tenancy in Relational Database (oracle,mysql,sqlserver etc.,)

1. Using single database :  Can be achieved by having tenant id in all your tables. But this method makes your maintenance very difficult.

Below is a sample architecture for achieving multi-tenancy using single database

img1

2. Using multiple database: The best method is to have a tenant master database and individual application databases for each tenant. The Tenant master database shall have following tables.

img2

Below is a sample data structure to handle this

a) Tenant Details : This table will have the list of tenants enrolled in the service. The table shall contain attributes like(Tenantid, TenantName, TenantType, Status, Created date etc.,)

b) Role: This table will have the list of roles. This shall be below the tenant level. So tenantid will be a foreign key here. The table shall contain attributes like(Roleid, Rolename,tenantid)

c) Policy: (This will define different level access rights of functions in the application)

Policies are defined for every functions in the software. Policies can also be defined to the level of data  ie using policy we can restrict access to certain data in terms of CRUD operations.

d) Role policy mapping (RoleId, policyid)

e) UserDetails (Tenantid, Userid,UserName,Password, etc.,)

In addition to the above tables, we can also maintain user login details with ip address, time, etc., in this database which may help in quantifying the usage. The application database names can be prefixed with tenantids.

Achieving multi-tenancy in NOSQL Database (I have Taken mongoDB as example)

The above functionality can be achieved in NOSQL database (mongoDB) by using below data structure.

Tenant   [ { TenantID: “1”},{TenantName:”xyz”}, {.. etc}]

Role {RoleID:”1″}, { TenantID: “”},{RoleName:,”admin”},policy[1,2,3,4]

Policy {[{policyid: “1”}{FunctionName: “Changepassword”}, access:[“create”,”delete”,”update”,”View”]]}, {[{policyid: “2”}{FunctionName: “user”}, access:[“create”,”delete”,”update”,”View”]]}

User {userid: “” },{username:”xyz”},{Roleid:””}..

Happy reading…

By

Shankar

http://www.cloudenablers.com/blog

Leave a Comment

Start typing and press Enter to search