Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Enabling Multi-Tenancy in Web Applications

The ability to share hardware, software, application development, and maintenance results in cost savings.


advertisement
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){  } %> <html> <head> <img src="<%=pro.getProperty("logo")%>"  width="150" height="50" border="2"> <title><%=pro.getProperty("title")%> Course List Page</title> </head>               </html>

Code snippets -- Business layer

<%  if (pro.getProperty("research")!=null){ %>   <url id="researchURL" action="research">   </url>   <a href="%{researchURL}">Research</s:a> <%}%> 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.


   
Ramasubramanian Thiyagarajan is a senior software engineer involved in the design and development of Java EE applications.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap