Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

One App, Many Clients: Converting an APEX Application to Multi-Tenant


Published on

When the director of a multi-sport event asked me to build an online registration system, I decided to build one that would not only serve that organisation, but could also be customised and re-used for other similar events around Australia. Since 2013 the "GamesFest" system has been used for up to 7 events run by 3 different organisations, each year.

GamesFest v1 was an APEX application which I would customise for each organisation using the "Copy Application" feature. This soon became unwieldy, however, as every bug fix or enhancement needed to be re-done in each Copy. GamesFest v2 was a partial re-write, a single APEX application using a different approach which gives the best of both worlds; all clients get bugfixes and enhancements immediately, while preserving their customisations.

This talk will compare and contrast the two approaches and will hopefully give APEX developers ideas they can implement or adapt for their own situations.

Follow-up blog article:

Published in: Software
  • Be the first to comment

One App, Many Clients: Converting an APEX Application to Multi-Tenant

  1. 1. One Application, Many Clients: Building a Multi-Tenant APEX Application Jeffrey Kemp
  2. 2. Version 1.0
  3. 3. customisations customisations customisations customisations customisations customisations APEX_APPLICATION.g_flow_alias Version 1.0
  4. 4. Version 1.1
  5. 5. Change Deployment • WWV_FLOW_UTILITIES.export_application_to_clob
  6. 6. Change Deployment • Prepend: set serverout on begin apex_pkg.pre_import (app_id => 323 ,app_alias => 'SYG' ,app_name => 'State Youth Games'); end; /
  7. 7. search and replace
  8. 8. customisations SYS_CONTEXT('CTX','ORG_YEAR') if minor_version >= 35 then ... end if Version 1.1
  9. 9. Version 2.0
  10. 10.
  11. 11. data-driven customisations SYS_CONTEXT('CTX','ORG_YEAR') Version 2.0
  12. 12. Multi-Tenant: Purpose • Partition the Data • Partition the Workload
  13. 13. Multi-Tenant: Design Goals 1. Tenant isolation 2. Cloud resource cost 3. Ease of administration 4. Scalability
  14. 14. Tenant Isolation • Data isolation • Backup & Restore • Customisations • Noisy neighbours • Data ownership
  15. 15. Hadlow's First Law of Multi-Tenancy “A multi-tenanted application should not look like a multi-tenanted application.”
  16. 16. Multi-Tenant: Architecture • Multiple servers • Multiple databases • Multiple workspaces/schemas • Single schema
  17. 17. Multi-Tenant: Single Schema Architectures • Separate tables for each tenant e.g. TENANT01_EMP, TENANT02_EMP, etc. “I have been involved in five different projects in which each user, or survey, or client, or whatever got their own set of tables. In each case this has been disasterous [sic]. In each case, the project was later re- engineered to use a generic, static schema.” [online discussion] • Tenant identifier column
  18. 18. Codebase Structure • Branch per tenant OR • Single codebase
  19. 19. “... per-tenant customisation is pretty much forbidden, everything that a tenant might want to change should be configurable ... You can maintain maybe 5 branches of a system, but not 15000, and that is what SaaS is aimed at” [Daniel B, multitenancy]
  20. 20. Multi-Tenant: Oracle Features For multiple databases/schemas: • Pluggable databases (Oracle Multitenant) • Application Containers (Oracle 12.2) • Conditional compilation
  21. 21. Multi-Tenant: Oracle Features For single schema: • [Global] Application Context • Row Level Security (VPD) • Views (poor-man's VPD) • Partitioned tables
  22. 22. Multi-Tenant: APEX Features • Workspace per tenant • Application per tenant • Single application/workspace
  23. 23. Convert an APEX Application to Multi-Tenant APEX changes • post-authentication: set application context variable
  24. 24. Convert an APEX Application to Multi-Tenant Data Model changes • Security groups table • Add column security_group_id
  25. 25. Convert an APEX Application to Multi-Tenant Security (Tenant isolation) • VPD policy for queries function vpd_policy (object_schema in varchar2 ,object_name in varchar2 ) return varchar2 is begin return q'[ security_group_id = sys_context('CTX’, 'SECURITY_GROUP_ID’) ]'; end vpd_policy; begin dbms_rls.add_policy (object_name => 'MYTABLE' ,policy name => 'multitenant_policy' ,policy_function => 'pkg.vpd_policy' ,update_check => true ,static_policy => true); end;
  26. 26. Convert an APEX Application to Multi-Tenant Constraint changes • Unique constraints fix_unique_constraint.sql • Referential constraints
  27. 27. Details “Convert an APEX Application to Multi-Tenant”
  28. 28. Thank you