This document discusses multi-tenancy in OutSystems, which allows a single application to provide isolated resources for each customer. It describes how to set the multi-tenant property, create tenants and user providers, and ensure entities, timers, and site properties are partitioned correctly for each tenant. The tenant ID attribute is used to filter data queries for each tenant.
1. | Tenants: A Look Behind The Scenes
Tenants: A Look Behind
The Scenes
2. | 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
3. | 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.
4. | Tenants: A Look Behind The Scenes
Demo
Let's create a simple multi-tenant application.
5. | Tenants: A Look Behind The Scenes
Product
Category
Multi-Tenancy
Users
ACME Syrius Stark
6. | 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
7. | Tenants: A Look Behind The Scenes
How to Create Them?
TenantCreate
8. | 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
9. | Tenants: A Look Behind The Scenes
Same app, but different Tenants,
thus different Data
10. | 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
11. | Tenants: A Look Behind The Scenes
Site Properties
● Not Multi-Tenant
○ One variable
● Multi-Tenant
○ One variable per tenant
12. | 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
13. | 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
15. | Tenants: A Look Behind The Scenes
Person Data with TenantId
16. | 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
17. | Tenants: A Look Behind The Scenes
Entity Espace_Tenant
● Read-only entity
● View that relates the Tenant with
the User Provider Espace
18. | 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
19. | Tenants: A Look Behind The Scenes
Creating a User
Provider
(simple way)
● Clone Users
● Change name
● Publish it
20. | 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
21. | Tenants: A Look Behind The Scenes
Creating a User Provider
(what happens)
● It creates a new tenant that is a user provider
22. | Tenants: A Look Behind The Scenes
Creating a User Provider
(what happens)
● Your module have tenants that
relate to the user provider
23. | 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
24. | 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
25. | Tenants: A Look Behind The Scenes
Creating Tenant and User Manager
26. | 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
27. | 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
28. | 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
29. | 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
30. | Tenants: A Look Behind The Scenes
Thank You!
@ injose.costa@itup.pt /josecccosta
Notas del editor
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
logically partitioned by the platform, as if the other tenants' data doesn't exist at all
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...