SlideShare a Scribd company logo
MULTI-TENANCY
in Java applications

@ladislavGazo
gazo@seges.sk
THE APPLICATION
user
|
bunch of JavaScript
|
service
|
domain model
IMPLICATION
user1 ... userN
|
same bunch of JavaScript
|
service
|
ONE database
ONE APPLICATION TO RULE THEM ALL
The term multi-tenancy in general is applied to software
development to indicate an architecture in which a single running
instance of an application simultaneously serves multiple clients
(tenants).
This is highly common in SaaS solutions.
Isolating information (data, customizations, etc) pertaining to the
various tenants is a particular challenge in these systems.
SPLIT ME NOW!
user1 -> BA, user2 -> BA, user 3 -> KE, user 4 -> ZA
|
again the same JavaScript
|
(almost) the same service
|
DB (BA), DB (KE), DB (ZA)
a lot of "tenant" dependent data - high volumes
performance
separation -> easier backup and restore
scalability of front-end and service layer
HIBERNATE IS THE EASIEST
MULTI-TENANT CONFIGURATION
<rprynm=hbraemlieac"vle"AAAE /
poet ae"ient.utTnny au=DTBS" >
<rprynm=hbraetnn_dniirrsle"vle"ksgshodlnecniuainMlieatdniireovr /
poet ae"ient.eatietfe_eovr au=s.ee.rdeei.ofgrto.utTnnIetfeRsle" >

<rprynm=hbraemlitnn_oncinpoie"vle"r.ient.evc.dccnetossi
poet ae"ient.ut_eatcneto_rvdr au=oghbraesriejb.oncin.p.
DtSucBsdutTnnCnetoPoieIp"/
aaoreaeMlieatoncinrvdrml >

<rprynm=hbraecneto.aaore vle"aacm/n/dch"/
poet ae"ient.oncindtsuc" au=jv:opevjb/r >

<rprynm=hbraemlitnn.aaoreietfe_o_n"vle"eal"/
poet ae"ient.ut_eatdtsuc.dniirfray au=dfut >
SWITCH IT ON

hbraemlieac
ient.utTnny
CONFIGURE WHERE TO LOOK FOR THE
CURRENT TENANT IDENTIFIER

hbraetnn_dniirrsle
ient.eatietfe_eovr
WHERE ARE MY CONNECTIONS?

hbraemlitnn_oncinpoie
ient.ut_eatcneto_rvdr

Hibernate's
DataSourceBasedMultiTenantConnectionProviderImpl
utilizes JNDI lookups
POINT TO JNDI ROOT FOR DATASOURCES

hbraecneto.aaore
ient.oncindtsuc
... AND THE DEFAULT

hbraemlitnn.aaoreietfe_o_n
ient.ut_eatdtsuc.dniirfray

So in the end =

jv:opevjb/rdfut
aacm/n/dch/eal
BUT THERE ARE THINGS THAT DON'T WORK
EHCache configuration from previous version is different
Hibernate's internal schema update does not work
NPE !!! ........ who would have said that
MIGRATION
HIBERNATE EXPORTER
is not helpful
DO YOU HAVE ENVERS?
then you need custom exporter
IT IS EASY TO WRITE
but don't forget the AuditConfiguration
EbCniuainjaofgrto =nwEbCniuain)cniue
j3ofgrto pCniuain
e j3ofgrto(.ofgr(
uiNm,nl)
ntae ul;
Cniuainhbraeofgrto =jaofgrto
ofgrto ientCniuain
pCniuain
.eHbraeofgrto(;
gtientCniuain)
hbraeofgrto.ulMpig(;
ientCniuainbidapns)
Adtofgrto adtofgrto =Adtofgrto.eFr
uiCniuain uiCniuain
uiCniuaingto(
hbraeofgrto)
ientCniuain;

and use EnversSchemaGenerator at last
GET RID OF NPE BUG

{"ient.utTnny,
hbraemlieac"
"ient.eatietfe_eovr,
hbraetnn_dniirrsle"
"ient.ut_eatcneto_rvdr,
hbraemlitnn_oncinpoie"
"ient.oncindtsuc"
hbraecneto.aaore,
"ient.ut_eatdtsuc.dniirfray }
hbraemlitnn.aaoreietfe_o_n"
RUN THE EXPORTER FROM MAVEN
COMBINE IT WITH LIQUIBASE

version 3.0.6 contains feature to populate all tenant databases
Mlieatpigiubs
utTnnSrnLqiae
DON'T FORGET...
it is maintenable but generated SQL needs to be checked
existing databases must be moved to "point 0"
A BIT OF LOGGING
http://www.slf4j.org/faq.html#logging_performance
Importance of logging - using MDC to track requests
MCpt"eat,cinOg)
D.u(tnn" letrz;

lgjapne.totlyu.ovrinatr =AP[dIO61]-%5
o4.pedrsdu.aotCnesoPten
P %{S80}
-p
[t%{eat|Xrqetd]%:M%3.0{}-%%
%|Xtnn}%{eusI} F% -03c1
mn
AND THE MOST BORING...

DESIGN
your app to be multi-tenant
SEND TENANT IDENTIFICATION
in HTTP Header
use Filter to get it out
in Service parameters
using ThreadLocal variable
via tenant-URL-based service calls
rmi://localhost:12345/<tenant>/<service>
etc...
THANKS FOR LISTENING

@ladislavGazo
gazo@seges.sk

More Related Content

PPTX
Terraform Basics
PPT
SSL Implementation - IBM MQ - Secure Communications
PDF
Open Service Broker APIとKubernetes Service Catalog #k8sjp
PDF
Auto scaling using Amazon Web Services ( AWS )
PPTX
HDFS: Optimization, Stabilization and Supportability
PDF
Kubernetes dealing with storage and persistence
PPTX
Amazon Virtual Private Cloud VPC Architecture AWS Web Services
PDF
Bringing Kafka Without Zookeeper Into Production with Colin McCabe | Kafka Su...
Terraform Basics
SSL Implementation - IBM MQ - Secure Communications
Open Service Broker APIとKubernetes Service Catalog #k8sjp
Auto scaling using Amazon Web Services ( AWS )
HDFS: Optimization, Stabilization and Supportability
Kubernetes dealing with storage and persistence
Amazon Virtual Private Cloud VPC Architecture AWS Web Services
Bringing Kafka Without Zookeeper Into Production with Colin McCabe | Kafka Su...

What's hot (20)

PDF
농심 그룹 메가마트 : 온프레미스 Exadata의 AWS 클라우드 환경 전환 사례 공유-김동현, NDS Cloud Innovation Ce...
PPTX
Infrastructure as Code in AWS using Cloudformation
PDF
Microservice With Spring Boot and Spring Cloud
PDF
AWS Fargate on EKS 실전 사용하기
PPT
Auto Scaling on AWS
PDF
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
PPTX
Prometheus design and philosophy
PDF
Trace Scheduling
PPTX
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
PPTX
Terraform
PDF
Prometheus - basics
PDF
EMR 플랫폼 기반의 Spark 워크로드 실행 최적화 방안 - 정세웅, AWS 솔루션즈 아키텍트:: AWS Summit Online Ko...
POTX
IBM Domino / IBM Notes Performance Tuning
PDF
인프라 벤치마크 테스트 잘 해보기 윤서율.pdf
PDF
AWS Backup을 이용한 데이터베이스의 백업 자동화와 편리한 복구방법
PDF
From A to Z-itrix: Setting up the most stable and fastest HCL Notes client on...
PDF
AWS AutoScaling
PDF
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
PPTX
MySQL Slow Query log Monitoring using Beats & ELK
PDF
Redo log
농심 그룹 메가마트 : 온프레미스 Exadata의 AWS 클라우드 환경 전환 사례 공유-김동현, NDS Cloud Innovation Ce...
Infrastructure as Code in AWS using Cloudformation
Microservice With Spring Boot and Spring Cloud
AWS Fargate on EKS 실전 사용하기
Auto Scaling on AWS
Amazon EMR과 SageMaker를 이용하여 데이터를 준비하고 머신러닝 모델 개발 하기
Prometheus design and philosophy
Trace Scheduling
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Terraform
Prometheus - basics
EMR 플랫폼 기반의 Spark 워크로드 실행 최적화 방안 - 정세웅, AWS 솔루션즈 아키텍트:: AWS Summit Online Ko...
IBM Domino / IBM Notes Performance Tuning
인프라 벤치마크 테스트 잘 해보기 윤서율.pdf
AWS Backup을 이용한 데이터베이스의 백업 자동화와 편리한 복구방법
From A to Z-itrix: Setting up the most stable and fastest HCL Notes client on...
AWS AutoScaling
Amazon DocumentDB vs MongoDB 의 내부 아키텍쳐 와 장단점 비교
MySQL Slow Query log Monitoring using Beats & ELK
Redo log
Ad

Viewers also liked (20)

PDF
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
PPTX
Multi Tenancy In The Cloud
PDF
How to build customizable multitenant web applications - IPC11 Spring Edition
PPTX
Multi-Tenant Approach
PDF
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
PDF
Multi-tenancy in the cloud
PDF
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
PDF
JVM Multitenancy (JavaOne 2012)
PPTX
Multi-Tenancy with Spring Boot
PPT
Making Apache Tomcat Multi-tenant, Elastic and Metered
PPT
Multi-tenancy In the Cloud
PPTX
Multi tenant architecture
ODP
Multi-Tenant SOA Middleware for Cloud Computing
PDF
Suportando Aplicações Multi-tenancy com Java EE
PPTX
A Multi-tenant Architecture for Business Process Executions
PDF
RESTful API Design, Second Edition
PPTX
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
PDF
Testing untestable code - phpday
PDF
How to build customizable multitenant web applications - PHPBNL11
PDF
Java EE 7 - Novidades e Mudanças
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
Multi Tenancy In The Cloud
How to build customizable multitenant web applications - IPC11 Spring Edition
Multi-Tenant Approach
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Multi-tenancy in the cloud
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
JVM Multitenancy (JavaOne 2012)
Multi-Tenancy with Spring Boot
Making Apache Tomcat Multi-tenant, Elastic and Metered
Multi-tenancy In the Cloud
Multi tenant architecture
Multi-Tenant SOA Middleware for Cloud Computing
Suportando Aplicações Multi-tenancy com Java EE
A Multi-tenant Architecture for Business Process Executions
RESTful API Design, Second Edition
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Testing untestable code - phpday
How to build customizable multitenant web applications - PHPBNL11
Java EE 7 - Novidades e Mudanças
Ad

Similar to Multi-tenancy in Java (20)

PDF
JVM Support for Multitenant Applications - Steve Poole (IBM)
PDF
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
PPTX
Tenants: A Look Behind the Scenes
PDF
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
PPT
PDF
Henry been database-per-tenant with 50k databases
PPTX
Building a multi-tenant application using 45.000 databases - Henry Been - Cod...
PDF
Multitenant applications: How and Why
PPTX
“Salesforce Multi-tenant architecture”,
PDF
Multitenancy con múltiples Bases de Datos
PDF
PDF
Athena java dev guide
PPTX
Create a simple multitenant application with entity framework
PDF
Hibernate complete notes_by_sekhar_sir_javabynatara_j
PDF
Hibernate complete notes_by_sekhar_sir_javabynatara_j
PPTX
Module-3 for career and JFSD ppt for study.pptx
PPT
Slice: OpenJPA for Distributed Persistence
PDF
Understanding the Salesforce Architecture: How We Do the Magic We Do
PPTX
What is Multi-Tenant Architecture ?
DOC
Hibernate tutorial for beginners
JVM Support for Multitenant Applications - Steve Poole (IBM)
Schema-based multi-tenant architecture using Quarkus &amp; Hibernate-ORM.pdf
Tenants: A Look Behind the Scenes
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Henry been database-per-tenant with 50k databases
Building a multi-tenant application using 45.000 databases - Henry Been - Cod...
Multitenant applications: How and Why
“Salesforce Multi-tenant architecture”,
Multitenancy con múltiples Bases de Datos
Athena java dev guide
Create a simple multitenant application with entity framework
Hibernate complete notes_by_sekhar_sir_javabynatara_j
Hibernate complete notes_by_sekhar_sir_javabynatara_j
Module-3 for career and JFSD ppt for study.pptx
Slice: OpenJPA for Distributed Persistence
Understanding the Salesforce Architecture: How We Do the Magic We Do
What is Multi-Tenant Architecture ?
Hibernate tutorial for beginners

More from seges (8)

PDF
Spring Boot and Microservices
PDF
Automated Tomcat Management
PDF
Javist Being Cheftain
PDF
OSGi experiments
PDF
Internetová prítomnosť a content management
PDF
AngularJS first steps
PDF
GWT Workshop
PDF
Ako sme zistili ze asi robime Scrum
Spring Boot and Microservices
Automated Tomcat Management
Javist Being Cheftain
OSGi experiments
Internetová prítomnosť a content management
AngularJS first steps
GWT Workshop
Ako sme zistili ze asi robime Scrum

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Big Data Technologies - Introduction.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
“AI and Expert System Decision Support & Business Intelligence Systems”
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Big Data Technologies - Introduction.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding

Multi-tenancy in Java

  • 2. THE APPLICATION user | bunch of JavaScript | service | domain model
  • 3. IMPLICATION user1 ... userN | same bunch of JavaScript | service | ONE database
  • 4. ONE APPLICATION TO RULE THEM ALL The term multi-tenancy in general is applied to software development to indicate an architecture in which a single running instance of an application simultaneously serves multiple clients (tenants). This is highly common in SaaS solutions. Isolating information (data, customizations, etc) pertaining to the various tenants is a particular challenge in these systems.
  • 5. SPLIT ME NOW! user1 -> BA, user2 -> BA, user 3 -> KE, user 4 -> ZA | again the same JavaScript | (almost) the same service | DB (BA), DB (KE), DB (ZA)
  • 6. a lot of "tenant" dependent data - high volumes performance separation -> easier backup and restore scalability of front-end and service layer
  • 8. MULTI-TENANT CONFIGURATION <rprynm=hbraemlieac"vle"AAAE / poet ae"ient.utTnny au=DTBS" > <rprynm=hbraetnn_dniirrsle"vle"ksgshodlnecniuainMlieatdniireovr / poet ae"ient.eatietfe_eovr au=s.ee.rdeei.ofgrto.utTnnIetfeRsle" > <rprynm=hbraemlitnn_oncinpoie"vle"r.ient.evc.dccnetossi poet ae"ient.ut_eatcneto_rvdr au=oghbraesriejb.oncin.p. DtSucBsdutTnnCnetoPoieIp"/ aaoreaeMlieatoncinrvdrml > <rprynm=hbraecneto.aaore vle"aacm/n/dch"/ poet ae"ient.oncindtsuc" au=jv:opevjb/r > <rprynm=hbraemlitnn.aaoreietfe_o_n"vle"eal"/ poet ae"ient.ut_eatdtsuc.dniirfray au=dfut >
  • 10. CONFIGURE WHERE TO LOOK FOR THE CURRENT TENANT IDENTIFIER hbraetnn_dniirrsle ient.eatietfe_eovr
  • 11. WHERE ARE MY CONNECTIONS? hbraemlitnn_oncinpoie ient.ut_eatcneto_rvdr Hibernate's DataSourceBasedMultiTenantConnectionProviderImpl utilizes JNDI lookups
  • 12. POINT TO JNDI ROOT FOR DATASOURCES hbraecneto.aaore ient.oncindtsuc
  • 13. ... AND THE DEFAULT hbraemlitnn.aaoreietfe_o_n ient.ut_eatdtsuc.dniirfray So in the end = jv:opevjb/rdfut aacm/n/dch/eal
  • 14. BUT THERE ARE THINGS THAT DON'T WORK EHCache configuration from previous version is different Hibernate's internal schema update does not work NPE !!! ........ who would have said that
  • 17. DO YOU HAVE ENVERS? then you need custom exporter
  • 18. IT IS EASY TO WRITE but don't forget the AuditConfiguration EbCniuainjaofgrto =nwEbCniuain)cniue j3ofgrto pCniuain e j3ofgrto(.ofgr( uiNm,nl) ntae ul; Cniuainhbraeofgrto =jaofgrto ofgrto ientCniuain pCniuain .eHbraeofgrto(; gtientCniuain) hbraeofgrto.ulMpig(; ientCniuainbidapns) Adtofgrto adtofgrto =Adtofgrto.eFr uiCniuain uiCniuain uiCniuaingto( hbraeofgrto) ientCniuain; and use EnversSchemaGenerator at last
  • 19. GET RID OF NPE BUG {"ient.utTnny, hbraemlieac" "ient.eatietfe_eovr, hbraetnn_dniirrsle" "ient.ut_eatcneto_rvdr, hbraemlitnn_oncinpoie" "ient.oncindtsuc" hbraecneto.aaore, "ient.ut_eatdtsuc.dniirfray } hbraemlitnn.aaoreietfe_o_n"
  • 20. RUN THE EXPORTER FROM MAVEN
  • 21. COMBINE IT WITH LIQUIBASE version 3.0.6 contains feature to populate all tenant databases Mlieatpigiubs utTnnSrnLqiae
  • 22. DON'T FORGET... it is maintenable but generated SQL needs to be checked existing databases must be moved to "point 0"
  • 23. A BIT OF LOGGING http://www.slf4j.org/faq.html#logging_performance Importance of logging - using MDC to track requests MCpt"eat,cinOg) D.u(tnn" letrz; lgjapne.totlyu.ovrinatr =AP[dIO61]-%5 o4.pedrsdu.aotCnesoPten P %{S80} -p [t%{eat|Xrqetd]%:M%3.0{}-%% %|Xtnn}%{eusI} F% -03c1 mn
  • 24. AND THE MOST BORING... DESIGN your app to be multi-tenant
  • 25. SEND TENANT IDENTIFICATION in HTTP Header use Filter to get it out in Service parameters using ThreadLocal variable via tenant-URL-based service calls rmi://localhost:12345/<tenant>/<service> etc...