SlideShare uma empresa Scribd logo
1 de 72
Multi-Tenancy
Development, Challenges & Solutions.
About Me
& My Company & My Projects
Halil İbrahim Kalkan
▪ Github
@hikalkan
▪ Twitter
@hibrahimkalkan
▪ Email
halil.kalkan@volosoft.com
aspnetboilerplate.com
• 4.5 years of continuous development.
• 4,300+ stars on Github.
• 470,000+ downloads on Nuget.
NDC London 2018
aspnetzero.com
SaaS
Software as a Service
On-Premise / IaaS / PaaS / SaaS
SaaS
Concepts
▪ Tenant: An organization that uses the application/service
(and pay for it).
▪ Host: The organization that is responsible to provide the service
and manage all the tenants.
SaaS
Concepts
▪ Feature: A functionality of the application.
▪ Edition/Package: A set of the application
features.
▪ Subscription: Assigning a package to a
tenant for a period of time.
▪ Payment: A subscription has a price:
Monthly, Yearly, User based and so on..
Why Multi-Tenancy?
▪ Maximum Utilization.
▪ Low Costs.
▪ Easy to add a new client (tenant).
▪ All clients use the same application & version.
▪ Reduces maintenance & upgrade costs.
Difficulties
▪ Data Isolation.
▪ Performance: One tenant’s heavy
usage may effect the other tenants.
▪ Different client requirements,
configuration & customization.
▪ Security.
▪ Backup (per tenant?)
Multi-Tenancy
High-Level Architecture
Deployment / Database Options
Hybrid
Ideal Multi-Tenant Application
▪ Works exactly like on-premise: Separated users, permissions, data…
▪ Should be able to work as on-premise too.
▪ Should be developed independent from multi-tenancy. Multi-tenancy should be
implemented in the infrastructure/framework.
Stateless Application Design
▪ Application should be stateless!
▪ Main state origins:
▪ Http Request: Cookie, header, querystring, payload…
▪ Authentication Ticket
▪ Database: Relational, non-relational, file system…
▪ Cache: Distributed caches like Redis, Memcached.
Multi-Tenancy
Determine the Current Tenant
Determine the Current Tenant
▪ Sources
▪ Current Claims (if user has been authenticated)
▪ Subdomain (or domain): https://tenancy-name.mydomain.com
▪ Http Header: _tenant = “acme” (for API clients & SPAs)
▪ Http Cookie: _tenant = “acme” (for MVC applications)
▪ ASP.NET Core
▪ On-demand
▪ Middleware (after app.UseAuthentication())
Ambient Context Pattern (without it)
Ambient Context Pattern
Ambient Context Examples
▪ HttpContext (IHttpContextAccessor)
▪ CultureInfo.CurrentUICulture / Thread.CurrentThread.CurrentUICulture
▪ Thread.CurrentPrincipal
Implementation using AsyncLocal<T>
AsyncLocal<T> Alternatives
▪ Public static … Multi-threading problem!
▪ HttpContext: Web-depended!
▪ ThreadStatic / ThreadLocal<T>: Not async/await friendly!
ASP.NET Core Multi-Tenancy Middleware
ASP.NET Core Multi-Tenancy Middleware
Change Current Tenant
Change Current Tenant (Nested)
Change Current Tenant
Multi-Tenancy Middleware Implementation
UI Design to Select the Tenant
Multi-Tenancy
Database / Data Isolation
Dynamically Select the Connection String
Dynamically Select the Connection String
Dynamically Select the Connection String
Data Filtering: Manual Way
Automatic Data Filtering: Repository Pattern
Automatic Data Filtering: Repository Pattern
▪ Pros
▪ Easy to implement (especially using generic repository pattern - IRepository<TEntity>).
▪ ORM Independent (can be implemented for any ORM that supports IQueryable).
▪ Central data-access
▪ Cons
▪ Limited – Can be bypassed by directly using DbContext.
▪ Limited – Does not work for navigation properties.
▪ Open to leak (Repository developer may forget it).
Automatic Data Filtering: EF Core Global Filters
Automatic Data Filtering: EF Core Global Filters
▪ Pros
▪ Natively works with EF Core.
▪ Supports navigation properties as well.
▪ Cons
▪ Limited – does not support multiple filters and enable/disable individually (possible via
workarounds – may be directly supported in the future).
▪ Limited – Does not work if you directly work with SQL, stored procedures… etc.
▪ Not available for all ORMs and data access APIs (but available for EF Core,
NHibernate and even for EF 6.x)
Automatic Data Filtering: Other Options
▪ Row Level Security – Available for SQL Server and Azure SQL Database.
▪ Pros: Completely integrated to DBMS. Works for everything.
▪ Cons: Relatively complex to implement. Specific to DBMS.
▪ Azure Elastic Database Pool
▪ Pros: Dynamically create databases per tenant. Easily scale.
▪ Cons: Only for db per tenant scenario. Has it’s own API. Has limitations.
Setting Tenant Id for New Entities
▪ In DbContext.SaveChanges()
▪ Get new entities for change tracker,
find IMultiTenant entities,
set current TenantId.
▪ In it’s constructor.
▪ Why..?
Safe Way to Manipulate Data
Multi-Tenancy
Cache Isolation
Cache Isolation
▪ Key/Value Caches may share same data space for all tenants.
▪ Tenants may want to cache same type of data with same id (unique per tenant).
Multi-Tenancy
Enable/Disable
Disable/Enable By Scope
▪ May need to query on all tenants.
▪ Can be implemented using ambient
context pattern.
▪ Problem: Not easy for multi-database
scenario.
Globally Disable
▪ May want to run the application as on-premise.
▪ Every table still has the TenantId column (with null values).
Multi-Tenancy
Database Transactions
Single Database / Multiple DbContext
▪ Multiple dbcontext can share single connection & transaction!
▪ EF Core 2.1 supports TransactionScope
Multiple Database / Distributed Transactions
▪ Multi-tenant (or host + tenant) operations may require distributed transactions
with database per tenant approach.
▪ SQL Server can handle but requires to run MSDTC.
▪ May not be possible for cloud platforms.
▪ Avoid where possible, or use event queues or some other async mechanism.
Multi-Tenancy
Database Migrations
Schema / Data Migration
▪ Problem for multiple-databases.
▪ Solution: Upgrade all in one with a custom tool.
▪ Pros: Easy to implement. All tenants are in the same version.
▪ Cons: May get too long time for big number of tenants and data. All tenants wait for all
upgrade progress.
▪ Solution: Upgrade the application servers immediately, upgrade databases
individually on first access.
▪ Pros: Upgrading is distributed to time. A tenant does not wait for another.
▪ Cons: First accessing user may wait too much. Even we get timeout exception. Also, we
don’t control the upgrade speed.
Schema / Data Migration
▪ Solution: Multiple versions concurrently.
▪ Split the application servers into two parts: Upgraded tenants use the new application,
other tenants use the old application.
▪ Pros:
▪ Minimum waiting for every tenant.
▪ Upgrading may be scheduled for every individual tenant and they can be informed.
▪ Allows us to perform A/B tests and previews.
▪ Cons
▪ Requires multiple application servers – but reasonable for a big system.
▪ Harder to implement, maintain and monitor.
Multi-Tenancy
Best Practices, Optimizations & Integrations
Separate Host & Tenant Application
▪ Create two applications, deploy individually:
▪ Tenant application: The actual business application.
▪ Can be deployed as on-premise too.
▪ Host application: The application used by the host users to manage tenants.
▪ Do not include in an on-premise deployment.
▪ Separate data schema & database from the tenant application.
▪ Store tenancy-related data: Tenants, Subscriptions, Payments, Editions… etc.
▪ Reduces tenant context switch by design.
ASP.NET Core Identity Integration
IdentityServer4 Integration
Partition Tables / Indexes by TenantId
▪ Create partitions for all (or big) tables by TenantId.
▪ Or Create TenantId indexes.
Multi-Tenancy
SaaS Features
Feature / Package / Subscription System
▪ Define features of the application. Feature Types:
▪ On/Off: Excel export, Replying by email (for a support app)…
▪ Numeric:10 users, 20,000 emails/month…
▪ Selection: one of the available options.
▪ Group features into packages/editions.
▪ Subscribe packages by tenants.
▪ Check features: Declarative or by code
Feature Checking
Declarative Feature Check
Implementation Options
▪ MVC Action Filters
▪ Easy to implement. Naturally works within ASP.NET Core.
▪ Limited to Controller actions.
▪ Method Interception using dynamic proxying.
▪ Works everywhere.
▪ Limited to virtual methods.
▪ Weaving: Mono.Cecil, Fody, Postsharp… etc.
Method Interception
Multi-Tenancy
Miscellaneous
Primary Keys
▪ GUID compared to auto increment (int/long)
▪ Pros
▪ Client can determine the value. No need to database roundtrip.
▪ Allows us to use dbcontext.SaveChanges() only once.
▪ Unique values even between tenants.
▪ Easier to merge/split/replicate databases.
▪ Cons
▪ More data space (16 bytes to 4/8 bytes).
▪ Gray Area
▪ Not user/debug friendly Id values. But it’s more secure!
▪ Notes
▪ Should use sequential algorithms (important for clustered indexes).
Background Jobs / Workers / Services
▪ No ambient tenant context!
▪ Shared pool of threads between tenants?
Configuration/Settings
▪ Tenant based settings may override global settings (Ex: password complexity).
▪ Some settings may be invisible from tenants (Ex: SMTP password).
▪ Setting fallback: User > Tenant > Global (host) > Hard-Coded (Ex: menu position)
▪ Branding: Tenant logo, colors… etc.
Tenant Plug-ins/Services
▪ How to use different/custom services for different tenants.
▪ Tenant-aware dependency injection.
▪ Application container per tenant?
▪ Combined with Elastic database pool.
▪ Possibility for multi-versioning.
▪ Possibility of loading application with tenant-specific plug-ins.
▪ Different tenants may have different database schemas.
Multi-tenancy With Microservices
▪ In case of every service has its own database combined with database per
tenant?
Thank you…
Github @hikalkan
Twitter @hibrahimkalkan
Email halil.kalkan@volosoft.com

Mais conteúdo relacionado

Mais procurados

Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Lucas Jellema
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices Bozhidar Bozhanov
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice ArchitectureNguyen Tung
 
VMware Tanzu Kubernetes Connect
VMware Tanzu Kubernetes ConnectVMware Tanzu Kubernetes Connect
VMware Tanzu Kubernetes ConnectVMware Tanzu
 
How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...
How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...
How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...Amazon Web Services
 
Running Mission Critical Workloads on AWS
Running Mission Critical Workloads on AWSRunning Mission Critical Workloads on AWS
Running Mission Critical Workloads on AWSAmazon Web Services
 
Case Study: How to move from a Monolith to Cloud, Containers and Microservices
Case Study: How to move from a Monolith to Cloud, Containers and MicroservicesCase Study: How to move from a Monolith to Cloud, Containers and Microservices
Case Study: How to move from a Monolith to Cloud, Containers and MicroservicesKai Wähner
 
Multi-tenancy In the Cloud
Multi-tenancy In the CloudMulti-tenancy In the Cloud
Multi-tenancy In the Cloudsdevillers
 
cloud-migrations.pptx
cloud-migrations.pptxcloud-migrations.pptx
cloud-migrations.pptxJohn Mulhall
 
Multitenancy on EKS
Multitenancy on EKSMultitenancy on EKS
Multitenancy on EKSIan Crosby
 
An introduction to terraform
An introduction to terraformAn introduction to terraform
An introduction to terraformJulien Pivotto
 
Cloud Native Applications Maturity Model
Cloud Native Applications Maturity ModelCloud Native Applications Maturity Model
Cloud Native Applications Maturity ModelJim Bugwadia
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to MicroservicesMahmoudZidan41
 
AWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 Barcelona
AWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 BarcelonaAWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 Barcelona
AWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 BarcelonaAmazon Web Services
 

Mais procurados (20)

Terraform
TerraformTerraform
Terraform
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
 
VMware Tanzu Kubernetes Connect
VMware Tanzu Kubernetes ConnectVMware Tanzu Kubernetes Connect
VMware Tanzu Kubernetes Connect
 
How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...
How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...
How a Global Healthcare Company Built a Migration Factory to Quickly Move Tho...
 
Running Mission Critical Workloads on AWS
Running Mission Critical Workloads on AWSRunning Mission Critical Workloads on AWS
Running Mission Critical Workloads on AWS
 
Intro - Cloud Native
Intro - Cloud NativeIntro - Cloud Native
Intro - Cloud Native
 
Case Study: How to move from a Monolith to Cloud, Containers and Microservices
Case Study: How to move from a Monolith to Cloud, Containers and MicroservicesCase Study: How to move from a Monolith to Cloud, Containers and Microservices
Case Study: How to move from a Monolith to Cloud, Containers and Microservices
 
Multi-tenancy In the Cloud
Multi-tenancy In the CloudMulti-tenancy In the Cloud
Multi-tenancy In the Cloud
 
cloud-migrations.pptx
cloud-migrations.pptxcloud-migrations.pptx
cloud-migrations.pptx
 
Why to Cloud Native
Why to Cloud NativeWhy to Cloud Native
Why to Cloud Native
 
Terraform
TerraformTerraform
Terraform
 
Multitenancy on EKS
Multitenancy on EKSMultitenancy on EKS
Multitenancy on EKS
 
An introduction to terraform
An introduction to terraformAn introduction to terraform
An introduction to terraform
 
Cloud Native Applications Maturity Model
Cloud Native Applications Maturity ModelCloud Native Applications Maturity Model
Cloud Native Applications Maturity Model
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
AWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 Barcelona
AWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 BarcelonaAWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 Barcelona
AWS App Mesh (Service Mesh Magic)- AWS Container Day 2019 Barcelona
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 

Semelhante a Multi-Tenancy

Towards the Cloud: Architecture Patterns and VDI Story
Towards the Cloud: Architecture Patterns and VDI StoryTowards the Cloud: Architecture Patterns and VDI Story
Towards the Cloud: Architecture Patterns and VDI StoryIT Expert Club
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - TalkMatthias Noback
 
Serverless at Lifestage
Serverless at LifestageServerless at Lifestage
Serverless at LifestageBATbern
 
How Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and ManagersHow Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and ManagersEDB
 
Cloudy in Indonesia: Java and Cloud
Cloudy in Indonesia: Java and CloudCloudy in Indonesia: Java and Cloud
Cloudy in Indonesia: Java and CloudEberhard Wolff
 
RedisConf18 - Common Redis Use Cases for Cloud Native Apps and Microservices
RedisConf18 - Common Redis Use Cases for Cloud Native Apps and MicroservicesRedisConf18 - Common Redis Use Cases for Cloud Native Apps and Microservices
RedisConf18 - Common Redis Use Cases for Cloud Native Apps and MicroservicesRedis Labs
 
SAP Teched 2012 Session Tec3438 Automate IaaS SAP deployments
SAP Teched 2012 Session Tec3438 Automate IaaS SAP deploymentsSAP Teched 2012 Session Tec3438 Automate IaaS SAP deployments
SAP Teched 2012 Session Tec3438 Automate IaaS SAP deploymentsChris Kernaghan
 
The twelve factor app
The twelve factor appThe twelve factor app
The twelve factor appInthra onsap
 
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...Serdar Basegmez
 
Making Apache Tomcat Multi-tenant, Elastic and Metered
Making Apache Tomcat Multi-tenant, Elastic and MeteredMaking Apache Tomcat Multi-tenant, Elastic and Metered
Making Apache Tomcat Multi-tenant, Elastic and MeteredPaul Fremantle
 
The Rocky Cloud Road
The Rocky Cloud RoadThe Rocky Cloud Road
The Rocky Cloud RoadGert Drapers
 
Praxistaugliche notes strategien 4 cloud
Praxistaugliche notes strategien 4 cloudPraxistaugliche notes strategien 4 cloud
Praxistaugliche notes strategien 4 cloudRoman Weber
 
Docebo: history of a journey from legacy to serverless
Docebo: history of a journey from legacy to serverlessDocebo: history of a journey from legacy to serverless
Docebo: history of a journey from legacy to serverlessAWS User Group Italy
 
Serverless Compose vs hurtownia danych
Serverless Compose vs hurtownia danychServerless Compose vs hurtownia danych
Serverless Compose vs hurtownia danychThe Software House
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Derek Ashmore
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Jeremy Likness
 
Automating Infrastructure as a Service Deployments and monitoring – TEC213
Automating Infrastructure as a Service Deployments and monitoring – TEC213Automating Infrastructure as a Service Deployments and monitoring – TEC213
Automating Infrastructure as a Service Deployments and monitoring – TEC213Chris Kernaghan
 
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Binary Studio
 
Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Derek Ashmore
 

Semelhante a Multi-Tenancy (20)

Towards the Cloud: Architecture Patterns and VDI Story
Towards the Cloud: Architecture Patterns and VDI StoryTowards the Cloud: Architecture Patterns and VDI Story
Towards the Cloud: Architecture Patterns and VDI Story
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Serverless at Lifestage
Serverless at LifestageServerless at Lifestage
Serverless at Lifestage
 
How Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and ManagersHow Databases Work - for Developers, Accidental DBAs and Managers
How Databases Work - for Developers, Accidental DBAs and Managers
 
Cloudy in Indonesia: Java and Cloud
Cloudy in Indonesia: Java and CloudCloudy in Indonesia: Java and Cloud
Cloudy in Indonesia: Java and Cloud
 
RedisConf18 - Common Redis Use Cases for Cloud Native Apps and Microservices
RedisConf18 - Common Redis Use Cases for Cloud Native Apps and MicroservicesRedisConf18 - Common Redis Use Cases for Cloud Native Apps and Microservices
RedisConf18 - Common Redis Use Cases for Cloud Native Apps and Microservices
 
SAP Teched 2012 Session Tec3438 Automate IaaS SAP deployments
SAP Teched 2012 Session Tec3438 Automate IaaS SAP deploymentsSAP Teched 2012 Session Tec3438 Automate IaaS SAP deployments
SAP Teched 2012 Session Tec3438 Automate IaaS SAP deployments
 
Background processing with hangfire
Background processing with hangfireBackground processing with hangfire
Background processing with hangfire
 
The twelve factor app
The twelve factor appThe twelve factor app
The twelve factor app
 
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
IBM Connect 2017: Your Data In the Major Leagues: A Practical Guide to REST S...
 
Making Apache Tomcat Multi-tenant, Elastic and Metered
Making Apache Tomcat Multi-tenant, Elastic and MeteredMaking Apache Tomcat Multi-tenant, Elastic and Metered
Making Apache Tomcat Multi-tenant, Elastic and Metered
 
The Rocky Cloud Road
The Rocky Cloud RoadThe Rocky Cloud Road
The Rocky Cloud Road
 
Praxistaugliche notes strategien 4 cloud
Praxistaugliche notes strategien 4 cloudPraxistaugliche notes strategien 4 cloud
Praxistaugliche notes strategien 4 cloud
 
Docebo: history of a journey from legacy to serverless
Docebo: history of a journey from legacy to serverlessDocebo: history of a journey from legacy to serverless
Docebo: history of a journey from legacy to serverless
 
Serverless Compose vs hurtownia danych
Serverless Compose vs hurtownia danychServerless Compose vs hurtownia danych
Serverless Compose vs hurtownia danych
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
 
Automating Infrastructure as a Service Deployments and monitoring – TEC213
Automating Infrastructure as a Service Deployments and monitoring – TEC213Automating Infrastructure as a Service Deployments and monitoring – TEC213
Automating Infrastructure as a Service Deployments and monitoring – TEC213
 
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
 
Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10Writing microservices in Java -- Chicago-2015-11-10
Writing microservices in Java -- Chicago-2015-11-10
 

Último

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 

Último (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

Multi-Tenancy

  • 2. About Me & My Company & My Projects
  • 3. Halil İbrahim Kalkan ▪ Github @hikalkan ▪ Twitter @hibrahimkalkan ▪ Email halil.kalkan@volosoft.com
  • 4. aspnetboilerplate.com • 4.5 years of continuous development. • 4,300+ stars on Github. • 470,000+ downloads on Nuget.
  • 6.
  • 7.
  • 10. On-Premise / IaaS / PaaS / SaaS
  • 11. SaaS Concepts ▪ Tenant: An organization that uses the application/service (and pay for it). ▪ Host: The organization that is responsible to provide the service and manage all the tenants.
  • 12. SaaS Concepts ▪ Feature: A functionality of the application. ▪ Edition/Package: A set of the application features. ▪ Subscription: Assigning a package to a tenant for a period of time. ▪ Payment: A subscription has a price: Monthly, Yearly, User based and so on..
  • 13. Why Multi-Tenancy? ▪ Maximum Utilization. ▪ Low Costs. ▪ Easy to add a new client (tenant). ▪ All clients use the same application & version. ▪ Reduces maintenance & upgrade costs.
  • 14. Difficulties ▪ Data Isolation. ▪ Performance: One tenant’s heavy usage may effect the other tenants. ▪ Different client requirements, configuration & customization. ▪ Security. ▪ Backup (per tenant?)
  • 16. Deployment / Database Options Hybrid
  • 17. Ideal Multi-Tenant Application ▪ Works exactly like on-premise: Separated users, permissions, data… ▪ Should be able to work as on-premise too. ▪ Should be developed independent from multi-tenancy. Multi-tenancy should be implemented in the infrastructure/framework.
  • 18. Stateless Application Design ▪ Application should be stateless! ▪ Main state origins: ▪ Http Request: Cookie, header, querystring, payload… ▪ Authentication Ticket ▪ Database: Relational, non-relational, file system… ▪ Cache: Distributed caches like Redis, Memcached.
  • 20. Determine the Current Tenant ▪ Sources ▪ Current Claims (if user has been authenticated) ▪ Subdomain (or domain): https://tenancy-name.mydomain.com ▪ Http Header: _tenant = “acme” (for API clients & SPAs) ▪ Http Cookie: _tenant = “acme” (for MVC applications) ▪ ASP.NET Core ▪ On-demand ▪ Middleware (after app.UseAuthentication())
  • 21. Ambient Context Pattern (without it)
  • 23. Ambient Context Examples ▪ HttpContext (IHttpContextAccessor) ▪ CultureInfo.CurrentUICulture / Thread.CurrentThread.CurrentUICulture ▪ Thread.CurrentPrincipal
  • 25. AsyncLocal<T> Alternatives ▪ Public static … Multi-threading problem! ▪ HttpContext: Web-depended! ▪ ThreadStatic / ThreadLocal<T>: Not async/await friendly!
  • 32. UI Design to Select the Tenant
  • 34. Dynamically Select the Connection String
  • 35. Dynamically Select the Connection String
  • 36. Dynamically Select the Connection String
  • 38. Automatic Data Filtering: Repository Pattern
  • 39. Automatic Data Filtering: Repository Pattern ▪ Pros ▪ Easy to implement (especially using generic repository pattern - IRepository<TEntity>). ▪ ORM Independent (can be implemented for any ORM that supports IQueryable). ▪ Central data-access ▪ Cons ▪ Limited – Can be bypassed by directly using DbContext. ▪ Limited – Does not work for navigation properties. ▪ Open to leak (Repository developer may forget it).
  • 40. Automatic Data Filtering: EF Core Global Filters
  • 41. Automatic Data Filtering: EF Core Global Filters ▪ Pros ▪ Natively works with EF Core. ▪ Supports navigation properties as well. ▪ Cons ▪ Limited – does not support multiple filters and enable/disable individually (possible via workarounds – may be directly supported in the future). ▪ Limited – Does not work if you directly work with SQL, stored procedures… etc. ▪ Not available for all ORMs and data access APIs (but available for EF Core, NHibernate and even for EF 6.x)
  • 42. Automatic Data Filtering: Other Options ▪ Row Level Security – Available for SQL Server and Azure SQL Database. ▪ Pros: Completely integrated to DBMS. Works for everything. ▪ Cons: Relatively complex to implement. Specific to DBMS. ▪ Azure Elastic Database Pool ▪ Pros: Dynamically create databases per tenant. Easily scale. ▪ Cons: Only for db per tenant scenario. Has it’s own API. Has limitations.
  • 43. Setting Tenant Id for New Entities ▪ In DbContext.SaveChanges() ▪ Get new entities for change tracker, find IMultiTenant entities, set current TenantId. ▪ In it’s constructor. ▪ Why..?
  • 44. Safe Way to Manipulate Data
  • 46. Cache Isolation ▪ Key/Value Caches may share same data space for all tenants. ▪ Tenants may want to cache same type of data with same id (unique per tenant).
  • 48. Disable/Enable By Scope ▪ May need to query on all tenants. ▪ Can be implemented using ambient context pattern. ▪ Problem: Not easy for multi-database scenario.
  • 49. Globally Disable ▪ May want to run the application as on-premise. ▪ Every table still has the TenantId column (with null values).
  • 51. Single Database / Multiple DbContext ▪ Multiple dbcontext can share single connection & transaction! ▪ EF Core 2.1 supports TransactionScope
  • 52. Multiple Database / Distributed Transactions ▪ Multi-tenant (or host + tenant) operations may require distributed transactions with database per tenant approach. ▪ SQL Server can handle but requires to run MSDTC. ▪ May not be possible for cloud platforms. ▪ Avoid where possible, or use event queues or some other async mechanism.
  • 54. Schema / Data Migration ▪ Problem for multiple-databases. ▪ Solution: Upgrade all in one with a custom tool. ▪ Pros: Easy to implement. All tenants are in the same version. ▪ Cons: May get too long time for big number of tenants and data. All tenants wait for all upgrade progress. ▪ Solution: Upgrade the application servers immediately, upgrade databases individually on first access. ▪ Pros: Upgrading is distributed to time. A tenant does not wait for another. ▪ Cons: First accessing user may wait too much. Even we get timeout exception. Also, we don’t control the upgrade speed.
  • 55. Schema / Data Migration ▪ Solution: Multiple versions concurrently. ▪ Split the application servers into two parts: Upgraded tenants use the new application, other tenants use the old application. ▪ Pros: ▪ Minimum waiting for every tenant. ▪ Upgrading may be scheduled for every individual tenant and they can be informed. ▪ Allows us to perform A/B tests and previews. ▪ Cons ▪ Requires multiple application servers – but reasonable for a big system. ▪ Harder to implement, maintain and monitor.
  • 57. Separate Host & Tenant Application ▪ Create two applications, deploy individually: ▪ Tenant application: The actual business application. ▪ Can be deployed as on-premise too. ▪ Host application: The application used by the host users to manage tenants. ▪ Do not include in an on-premise deployment. ▪ Separate data schema & database from the tenant application. ▪ Store tenancy-related data: Tenants, Subscriptions, Payments, Editions… etc. ▪ Reduces tenant context switch by design.
  • 58. ASP.NET Core Identity Integration
  • 60. Partition Tables / Indexes by TenantId ▪ Create partitions for all (or big) tables by TenantId. ▪ Or Create TenantId indexes.
  • 62. Feature / Package / Subscription System ▪ Define features of the application. Feature Types: ▪ On/Off: Excel export, Replying by email (for a support app)… ▪ Numeric:10 users, 20,000 emails/month… ▪ Selection: one of the available options. ▪ Group features into packages/editions. ▪ Subscribe packages by tenants. ▪ Check features: Declarative or by code
  • 64. Declarative Feature Check Implementation Options ▪ MVC Action Filters ▪ Easy to implement. Naturally works within ASP.NET Core. ▪ Limited to Controller actions. ▪ Method Interception using dynamic proxying. ▪ Works everywhere. ▪ Limited to virtual methods. ▪ Weaving: Mono.Cecil, Fody, Postsharp… etc.
  • 67. Primary Keys ▪ GUID compared to auto increment (int/long) ▪ Pros ▪ Client can determine the value. No need to database roundtrip. ▪ Allows us to use dbcontext.SaveChanges() only once. ▪ Unique values even between tenants. ▪ Easier to merge/split/replicate databases. ▪ Cons ▪ More data space (16 bytes to 4/8 bytes). ▪ Gray Area ▪ Not user/debug friendly Id values. But it’s more secure! ▪ Notes ▪ Should use sequential algorithms (important for clustered indexes).
  • 68. Background Jobs / Workers / Services ▪ No ambient tenant context! ▪ Shared pool of threads between tenants?
  • 69. Configuration/Settings ▪ Tenant based settings may override global settings (Ex: password complexity). ▪ Some settings may be invisible from tenants (Ex: SMTP password). ▪ Setting fallback: User > Tenant > Global (host) > Hard-Coded (Ex: menu position) ▪ Branding: Tenant logo, colors… etc.
  • 70. Tenant Plug-ins/Services ▪ How to use different/custom services for different tenants. ▪ Tenant-aware dependency injection. ▪ Application container per tenant? ▪ Combined with Elastic database pool. ▪ Possibility for multi-versioning. ▪ Possibility of loading application with tenant-specific plug-ins. ▪ Different tenants may have different database schemas.
  • 71. Multi-tenancy With Microservices ▪ In case of every service has its own database combined with database per tenant?
  • 72. Thank you… Github @hikalkan Twitter @hibrahimkalkan Email halil.kalkan@volosoft.com