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:
Share on facebook
Share on twitter
Share on linkedin


The Latest

Top 5 B2B SaaS Marketing Agencies for 2023

In recent years, the software-as-a-service (SaaS) sector has experienced exponential growth as more and more companies choose cloud-based solutions. Any SaaS company hoping to stay ahead of the curve in this quickly changing industry needs to invest in effective marketing. So selecting the best marketing agency can mean the difference

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.