Enabling Multi-Tenancy in Web Applications

Enabling Multi-Tenancy in Web Applications

As you’re probably aware, Software as a Service (SaaS) is a deployment model by which service providers remotely host application over the Internet and service it on demand to one or more clients. Organizations leverage the SaaS model to trim IT cost associated with conventional live applications that feature hardware, patch management, upgrades, etc. License on demand will also provide the customer the model “pay as you go/grow,” thereby reducing their upfront expense for IT purchases.

Overview of Multi-Tenant Model

[login] Web-delivery solutions provides the ability to deliver software to multiple clients from single, shared instance which is the most significant requirement in recent times. The major advantages of multi-tenancy is in its cost-effectiveness. The ability to share hardware, software, application development, and maintenance cost amongst tenants in turn helps in significant reduction of cost. Apart from that, sharing a single instance of an application between tenants helps in migration initiatives as different tenants can be simultaneously upgraded.

Multi-Tenant Architecture Overview

The above architecture represents the sharing of all resources with each tenant. The tenants share the application server and access application resources through separate session or threads.

Multi-Tenant J2EE Architecture

The architecture diagram below provides a detailed explanation on how we can enable multi-tenancy in web applications:

Tenant configuration

The following are the ways in which we can identify the tenant from their request

    * Web server configuration
    * Tenant Configuration

Web server configuration for multi-tenant deployment

The Apache web server provides the means to configure a single application instance to different domain names. The application deployer should map the domains to each client which is used to retrieve the client identity information from their request

Tenant configuration in application

The application posts the tenant short name or id as part of the user request. The short name or id is used as a key to identify the tenant.

Tenant Filter

Tenant Filter is used to filter the user request and identify the tenant. Tenant filter will store the information specific to each tenant in the user session. This in turn helps in processing the request further for creating tenant context. The sample filter code below identifies the tenant during login:

User   user= UserDAO.getUser(req.getParameter("orgid"),req.getParameter("loginname"),req.getParameter("pass"));if(null != user){		HttpSession session = req.getSession(true);		session.setAttribute("context",user);		return SUCCESS;	}else{		return "fail";	}

Tenant Context

Tenant context is created based on the user request and specific to a session. The tenant context has information specific to tenant requirement and database configuration

Tenant Property Configuration

Configuration of property file in the form of key/value pair is mainly based on tenant requirements. The Property file will have tenant specific requirements. Using tenant context, application should identify property file for processing each layers like UI, Business, data etc. Sample tenant property file configuration From the table above, the title and logo are UI layer requirements:

    * Title and logo are used by the application for UI design.

Research and export are business requirements.

    * Research and Export helps to view the research details of the tenant and export the data specific to tenant.

Property files can be created for each layer depending upon the requirement. We can also use single property file to match the entire requirement.

Mapping Tenant Property Files with User Request

Code snippets -- UI Layer

<%	 String pagename="course";	 Properties pro=null;	 InputStream instream=null;	 try{	 	User user=(User)session.getAttribute("context");	 	String proFile="/WEB-INF/classes/prop/tenant_"+user.getTenantShort()+".properties";
  instream=application.getResourceAsStream(proFile); pro= new Properties();        pro.load(instream);  }catch(Exception ee){  } %> "  width="150" height="50" border="2"> <%=pro.getProperty("title")%> Course List Page               

Code snippets -- Business layer

	<%  if (pro.getProperty("research")!=null){ %>	   	    	   Research	<%}%>		HttpServletRequest req = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);	User user=(User)req.getSession().getAttribute("context");	researchList=courseDAO.getResearch(user);

Data Model Configuration for Multi-Tenant

Tenant's data can be managed in the following ways:

    * Shared database, shared schema and separate table: This helps to store tenant specific data in separate table.

    * Shared schema shared database and shared table: If tenant's transaction is minimum then you can use this type of approach.

    * Shared database and separate schema: It helps to enable security for tenant's data

    * Separate database: provides secured access for client/tenant's data.

The data model approach used for sample web application is shared database and shared tables for multi-tenant application. Data Model Scripts will give an clear understanding and way in which data model can be configured.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes