0
votes

I have a Java web application using JSF running on Tomcat 8.5. Each tenant has multiple users and is given their own URL, e.g:

example.com/tenant1 example.com/tenant2 ... example.com/tenant100

This is currently implemented by deploying the same WAR file once for each tenant, so we have

tenant1.war, tenant2.war, ... tenant100.war

Each tenant has their own schema on the same database with their own database login that the app uses via JNDI in Tomcat 8.5. It also uses container managed security to handle user login.

So far this works ok, but startup time is beginning to lag as more tenants (realms) are added - about 3 seconds per WAR file to be deployed. Is there a more efficient way to go about this so that we only use one WAR file, but still have separate databases (or schemas) and security to isolate tenants?

I see that Spring has an approach here and Hibernate multitenancy, but I'm not using JPA/Hibernate or Spring.

Currently running on Tomcat, but I can switch to Wildfly and use some other JEE solution if it exists.

Any more general architectural approaches are also appreciated.

1

1 Answers

0
votes

The best approach towards handling multi-tenancy is to have a single code base which is the highest level of multi-tenancy.

In your scenario, you can setup filters to intercept the incoming requests and then identify the segment 1 as the tenant name there by using the tenant information.

Once obtained, there will be a TenantContext that has the tenant information like the database schema etc. This can be used to set up the right data context for the queries to the database.

HTH