Multi-tenancy is important in the context of the Cloud. In the Cloud, all costs for hosting and operating software and its required technical resources are the responsibility of the application provider. Therefore, reducing these costs is essential for running a cloud business.
Multi-tenancy is defined as a software architecture in which the software is provided once on a server that serves multiple customers, referred to as tenants. The tenants share the same technical resources, but the data is separated, and identity and access management are strictly isolated.
Using a multi-tenant approach helps in reducing costs. The main cost drivers are operations and resources. Operational efforts are bug fixing, deploying new versions of an application, and monitoring the application. When there is only instance of software, the operations team has to update it only once, while all tenants benefit. The resource costs are caused by different technical components that are used for storing and processing data, like databases, message brokers, and so on, as well as the costs of running the application, for example, the application run-time is offered at a fixed price. Therefore, the more tenants that are served by a single server, the cheaper the operations and resources of the overall application.
Important Aspects of Multi-Tenancy
In general, to provide end-to-end multi-tenancy, developers need to consider several components in different application layers, depending on the nature and complexity of the application. Let us consider some important aspects that are relevant to this course.
Business Partner Address Manager: Before Introducing Multi-Tenancy
The following figure depicts the high-level components of the Business Partner Address Manager application, as well as the involved SAP Business Technology Platform and SAP S/4HANA services that are relevant in this context. Note that this application is without multi-tenancy. In the next figure, we introduce multi-tenancy to this application.
Business Partner Address Manager: After Introducing Multi-Tenancy
To introduce multi-tenancy, and to enrich the data and business process for this application, we use the database service of SAP Business Technology Platform.
On the API level, we introduce the additional endpoint, addresses-local. We provide this API to POST a new address and to change the address status from NEW to REJECTED or APPROVED.
In addition, the existing application logic and data model need to be extended. To achieve this, we integrate a persistence service of SAP Business Technology Platform, where we handle newly created business partner addresses and their current statuses, like NEW to REJECTED or APPROVED, in a separate local persistence service instance. Every time an address is approved, the creation of a corresponding record is triggered in SAP S/4HANA.
Steps to Implement Tenant-aware Persistence
Based on the sample application, let us explore some of the important aspects of multi-tenancy implementation.
In the first step, we configure the data source to access the corresponding PostgreSQL service in SAP Business Technology Platform, Cloud Foundry.
In the second step, we configure Hibernate for multi-tenancy, where we leverage the SDK component, Tenant Accessor, to access the tenant ID to make the implementation SAP Business Technology Platform edition-agnostic. In the first two steps, we have customized the tenant-aware processing of requests, meaning that each tenant is now redirected by Hibernate to its dedicated database schema. Another key aspect of the implementation is to ensure that the database schema and all related database objects exist for each new subscribed tenant.
In the third step, we create and register an API for tenant onboarding and offboarding, to ensure that an application running in SAP Business Technology Platform Cloud Foundry is being notified of each tenant subscription. This API is called by SAP Business Technology Platform each time, when an account subscribes to the application.
In the fourth step, we persist and access the data.