| Tenants: A Look Behind The Scenes
Tenants: A Look Behind
The Scenes
| Tenants: A Look Behind The Scenes| Tenants: A Look Behind The Scenes
José
Costa
OutSystems MVP, Senior Trainer | ITUp
@
in
jose.costa@itup.pt
/josecccosta
| Tenants: A Look Behind The Scenes
Multi-tenancy
Multi-tenancy enables a single application server and database
server to provide each customer with their own isolated set of
computing resources.
| Tenants: A Look Behind The Scenes
Demo
Let's create a simple multi-tenant application.
| Tenants: A Look Behind The Scenes
Product
Category
Multi-Tenancy
Users
ACME Syrius Stark
| Tenants: A Look Behind The Scenes
How to Develop
Using Them?
● Set the module Is Multi-tenant
property to Yes
● Entities, Timers and Site
Properties get the module
property by default or you can
(un)set those individually
| Tenants: A Look Behind The Scenes
How to Create Them?
TenantCreate
| Tenants: A Look Behind The Scenes
How to Use Them?
● Create users in the tenants
○ App Users does not do that (more on this later)
○ You need to create an app to do it or install one from Forge:
■ Application Framework, Multitenant Management, ...
● Login with a user and the app will use the data of the corresponding
tenant
| Tenants: A Look Behind The Scenes
Same app, but different Tenants,
thus different Data
| Tenants: A Look Behind The Scenes
Entities
● Not Multi-Tenant
○ Same data independently of the user logged in
○ All data is available
● Multi-Tenant
○ Different data depending on the tenant of the user that logged in
○ Only a subset of data is accessible
○ Data is logically partitioned by the platform
| Tenants: A Look Behind The Scenes
Site Properties
● Not Multi-Tenant
○ One variable
● Multi-Tenant
○ One variable per tenant
| Tenants: A Look Behind The Scenes
Timers
● Not Multi-Tenant
○ One instance of the timer runs
○ Uses data from tenant of User Provider
● Multi-Tenant
○ One instance of the timer per tenant runs for that tenant
○ Each instance uses data of that tenant
| Tenants: A Look Behind The Scenes
TenantId
● Attribute in entity that specifies
the tenant for each record
● Hidden
○ Queries for this Entity
automatically filtered by
TenantId
● Shown
○ Access to all data
| Tenants: A Look Behind The Scenes
Datamodel
| Tenants: A Look Behind The Scenes
Person Data with TenantId
| Tenants: A Look Behind The Scenes
Entity Tenant
Espace_Id
● User Provider
If Is_Active is False for that tenant:
● Users cannot login
● Multi-tenant Timers will not run
● Processes will not run
| Tenants: A Look Behind The Scenes
Entity Espace_Tenant
● Read-only entity
● View that relates the Tenant with
the User Provider Espace
| Tenants: A Look Behind The Scenes
User Providers
● Property in Service Studio
● Two by default (Users and Service
Center)
● Application through which you
manage your users
| Tenants: A Look Behind The Scenes
Creating a User
Provider
(simple way)
● Clone Users
● Change name
● Publish it
| Tenants: A Look Behind The Scenes
Creating a User Provider
(another way)
● Create new application
● Implement the type of login (and
UI) that you want
● Make it Multi-Tenant
● Check the "Is User Provider"
property
| Tenants: A Look Behind The Scenes
Creating a User Provider
(what happens)
● It creates a new tenant that is a user provider
| Tenants: A Look Behind The Scenes
Creating a User Provider
(what happens)
● Your module have tenants that
relate to the user provider
| Tenants: A Look Behind The Scenes
If No User Provider
● User Provider is own module
● Since all modules are tenants
○ useful for these situations
● Data is stored in tenant of the
module
○ even on single tenant apps
| Tenants: A Look Behind The Scenes
UserManager
● Useful in order to use Users to manage multi-tenant users
● Role of Users
● User with UserManager role can create/manage users in its tenant
● You can have an App that assigns the UserManager role to a user in the
tenant
○ When you create the tenant, create straightaway a user in that tenant
with role UserManager
| Tenants: A Look Behind The Scenes
Creating Tenant and User Manager
| Tenants: A Look Behind The Scenes
TenantSwitch
● System Action that allows you in
runtime to change the context
to the specified tenant
● Useful for example in your
custom Users Manager
application
○ Its Login action can use it
to switch to the Tenant of
the User that is logging in
● Note that it logs the user out and
| Tenants: A Look Behind The Scenes
From Single-Tenant to Multi-Tenant
● Entities are created without TenantId
● Entry in Entity Tenant is created for module
● Once Multi-Tenancy is set
○ TenantId is created and populated (with User Provider's Tenant)
○ One View per Tenant for each Entity is created is the database
| Tenants: A Look Behind The Scenes
Processes and Tenants
● Processes use the Tenant from which they started
● TenantSwitch only possible in the OnProcessStart event of the process
● Use the Expose TenantId to access other tenants' data
| Tenants: A Look Behind The Scenes
Issues
● I need physical Database separation
○ Not possible in main OutSystems database
○ But can be done using external database, and using the
SessionSetDBConnection to change the connection string to a
tenant-specific setting
● I need data stripping at low hierarchy levels but managers need to see all
data
○ Can be done with multi-tenancy and manager module(s) where
the tenant id is exposed
| Tenants: A Look Behind The Scenes
Thank You!
@ injose.costa@itup.pt /josecccosta

Tenants: A Look Behind the Scenes

  • 1.
    | Tenants: ALook Behind The Scenes Tenants: A Look Behind The Scenes
  • 2.
    | Tenants: ALook Behind The Scenes| Tenants: A Look Behind The Scenes José Costa OutSystems MVP, Senior Trainer | ITUp @ in jose.costa@itup.pt /josecccosta
  • 3.
    | Tenants: ALook Behind The Scenes Multi-tenancy Multi-tenancy enables a single application server and database server to provide each customer with their own isolated set of computing resources.
  • 4.
    | Tenants: ALook Behind The Scenes Demo Let's create a simple multi-tenant application.
  • 5.
    | Tenants: ALook Behind The Scenes Product Category Multi-Tenancy Users ACME Syrius Stark
  • 6.
    | Tenants: ALook Behind The Scenes How to Develop Using Them? ● Set the module Is Multi-tenant property to Yes ● Entities, Timers and Site Properties get the module property by default or you can (un)set those individually
  • 7.
    | Tenants: ALook Behind The Scenes How to Create Them? TenantCreate
  • 8.
    | Tenants: ALook Behind The Scenes How to Use Them? ● Create users in the tenants ○ App Users does not do that (more on this later) ○ You need to create an app to do it or install one from Forge: ■ Application Framework, Multitenant Management, ... ● Login with a user and the app will use the data of the corresponding tenant
  • 9.
    | Tenants: ALook Behind The Scenes Same app, but different Tenants, thus different Data
  • 10.
    | Tenants: ALook Behind The Scenes Entities ● Not Multi-Tenant ○ Same data independently of the user logged in ○ All data is available ● Multi-Tenant ○ Different data depending on the tenant of the user that logged in ○ Only a subset of data is accessible ○ Data is logically partitioned by the platform
  • 11.
    | Tenants: ALook Behind The Scenes Site Properties ● Not Multi-Tenant ○ One variable ● Multi-Tenant ○ One variable per tenant
  • 12.
    | Tenants: ALook Behind The Scenes Timers ● Not Multi-Tenant ○ One instance of the timer runs ○ Uses data from tenant of User Provider ● Multi-Tenant ○ One instance of the timer per tenant runs for that tenant ○ Each instance uses data of that tenant
  • 13.
    | Tenants: ALook Behind The Scenes TenantId ● Attribute in entity that specifies the tenant for each record ● Hidden ○ Queries for this Entity automatically filtered by TenantId ● Shown ○ Access to all data
  • 14.
    | Tenants: ALook Behind The Scenes Datamodel
  • 15.
    | Tenants: ALook Behind The Scenes Person Data with TenantId
  • 16.
    | Tenants: ALook Behind The Scenes Entity Tenant Espace_Id ● User Provider If Is_Active is False for that tenant: ● Users cannot login ● Multi-tenant Timers will not run ● Processes will not run
  • 17.
    | Tenants: ALook Behind The Scenes Entity Espace_Tenant ● Read-only entity ● View that relates the Tenant with the User Provider Espace
  • 18.
    | Tenants: ALook Behind The Scenes User Providers ● Property in Service Studio ● Two by default (Users and Service Center) ● Application through which you manage your users
  • 19.
    | Tenants: ALook Behind The Scenes Creating a User Provider (simple way) ● Clone Users ● Change name ● Publish it
  • 20.
    | Tenants: ALook Behind The Scenes Creating a User Provider (another way) ● Create new application ● Implement the type of login (and UI) that you want ● Make it Multi-Tenant ● Check the "Is User Provider" property
  • 21.
    | Tenants: ALook Behind The Scenes Creating a User Provider (what happens) ● It creates a new tenant that is a user provider
  • 22.
    | Tenants: ALook Behind The Scenes Creating a User Provider (what happens) ● Your module have tenants that relate to the user provider
  • 23.
    | Tenants: ALook Behind The Scenes If No User Provider ● User Provider is own module ● Since all modules are tenants ○ useful for these situations ● Data is stored in tenant of the module ○ even on single tenant apps
  • 24.
    | Tenants: ALook Behind The Scenes UserManager ● Useful in order to use Users to manage multi-tenant users ● Role of Users ● User with UserManager role can create/manage users in its tenant ● You can have an App that assigns the UserManager role to a user in the tenant ○ When you create the tenant, create straightaway a user in that tenant with role UserManager
  • 25.
    | Tenants: ALook Behind The Scenes Creating Tenant and User Manager
  • 26.
    | Tenants: ALook Behind The Scenes TenantSwitch ● System Action that allows you in runtime to change the context to the specified tenant ● Useful for example in your custom Users Manager application ○ Its Login action can use it to switch to the Tenant of the User that is logging in ● Note that it logs the user out and
  • 27.
    | Tenants: ALook Behind The Scenes From Single-Tenant to Multi-Tenant ● Entities are created without TenantId ● Entry in Entity Tenant is created for module ● Once Multi-Tenancy is set ○ TenantId is created and populated (with User Provider's Tenant) ○ One View per Tenant for each Entity is created is the database
  • 28.
    | Tenants: ALook Behind The Scenes Processes and Tenants ● Processes use the Tenant from which they started ● TenantSwitch only possible in the OnProcessStart event of the process ● Use the Expose TenantId to access other tenants' data
  • 29.
    | Tenants: ALook Behind The Scenes Issues ● I need physical Database separation ○ Not possible in main OutSystems database ○ But can be done using external database, and using the SessionSetDBConnection to change the connection string to a tenant-specific setting ● I need data stripping at low hierarchy levels but managers need to see all data ○ Can be done with multi-tenancy and manager module(s) where the tenant id is exposed
  • 30.
    | Tenants: ALook Behind The Scenes Thank You! @ injose.costa@itup.pt /josecccosta

Editor's Notes

  • #4 To customers, it appears that they have their own application, when in fact they are using the same app as others but with some customization. So, same physical resources and application runtime, but isolated data
  • #11 logically partitioned by the platform, as if the other tenants' data doesn't exist at all
  • #16 This is a join of the Tenant with Person. Notice that if I do not expose the TenantId I also have to specify in Service Studio the Tenant that I want to use...
  • #17 TenantSwitch will also not work for that tenant.
  • #19 A User Provider is a Tenant
  • #27 TenantSwitch does a CommitTransaction