Multi-Tenant SaaS Architecture Design: Database Isolation, Security and Integration

multi-tenant SaaS architecture design
multi-tenant SaaS architecture design

A SaaS application can serve hundreds or thousands of businesses through one platform. Whilst multiple customers are able to utilise the same application infrastructure, it is vital that each customer can only view and interact with their own data, configuration and people, along with their associated applications/services.

Multi-tenancy is therefore key when designing SaaS.

A multi-tenant architecture allows multiple customers, known as tenants, to use the same software application while maintaining logical separation between their information and activities. In preference to providing and supporting individual applications for each customer, companies can provide a common infrastructure with specific tenant configuration and authorisation options.

Nevertheless, there are technical issues to address when multiple customers share infrastructure. These include the separation of data, user authentication, API authorisation, integration with external applications and application performance along with data synchronisation.

Poorly implemented tenant functionality may result in leakage of a customer’s information and/or one customer’s behaviour impacting another.

This article describes multi-tenancy and analyses different database approaches. It also looks at key design factors to enable the creation of secure, supportable and scalable SaaS applications.

What Is Multi-Tenant SaaS Architecture?

Multi-tenant SaaS application architecture
Multi-tenant SaaS application architecture

In multi-tenancy, a single SaaS programme is used by many different users. Separation of information and settings is provided for each user.

Each customer is called a tenant. Depending on the product, a tenant can be a company, organisation, government body, school or even a person.

For instance, if there was a project management SaaS service then the following 3 companies may all use it:

  • Company A handles staff, projects and work.
  • Company B runs its projects, groups and target dates.
  • Company C also utilises this system in house.

All three companies access the same software platform. Company A must also never be permitted to look at Company B’s information nor edit Company C’s details.

Generally, within a multi-tenant application there is a defined process for handling requests.

How Does Multi-Tenant Architecture Work?

A typical multi-tenant application follows a structured request-processing workflow.

  1. A user signs in to the application.
  2. Users are authenticated.
  3. The application determines which tenant or organization the user belongs to.
  4. Users are then authorised to determine which functionality they can access.
  5. The application retrieves tenant-specific information from the database.
  6. The requested operation is completed within the authorized tenant context.

When a user accesses a project dashboard, the application recognises which organisation they are part of and then fetches relevant project data.

The database query must be restricted to that tenant’s information. Application developers should not be solely responsible for including a tenant identifier within each query.

Database security can further enforce tenant isolation.

Good application architecture will also continue to recognise tenants when passing requests between different services, batch processes and third party systems.

Multi-Tenant vs. Single-Tenant SaaS Architecture

One of the first decisions when developing a SaaS product is whether customers should share an application environment or receive dedicated infrastructure.

There are both pros and cons associated with these methods.

Multi-Tenant Architecture

In a multi-tenant environment, multiple customers share application infrastructure, and the system separates their data through logical or physical isolation mechanisms.

Advantages:

  • Common infrastructure can help to save money.
  • Update processes can be centralised.
  • An organisation does not need to develop an entirely new application when adding further customers.
  • Common services allow more straightforward centralised tracking.
  • Customer accounts can all be controlled from one central area.

Limitations:

  • Tenant isolation requires careful implementation.
  • Common areas of an application may cause performance issues.
  • Tailoring is also something that will require further management.
  • A vulnerability within a common area can effect many different tenants.

Single-Tenant Architecture

In a single-tenant environment, each customer receives a dedicated application instance, database, or infrastructure environment.

Advantages:

  • Stronger physical separation when dedicated infrastructure is used.
  • Independent backup and restoration processes.
  • Greater flexibility for customer-specific configurations.
  • More control over resource allocation and maintenance schedules.

Limitations:

  • Infrastructure and maintenance costs can increase.
  • Further users will require further effort to manage.
  • Different environments also need updates and deployment.
  • In addition, monitoring and systems management can become more complex.

Which Architecture Should a SaaS Business Choose?

This will depend on the needs of a business rather than there being one ‘perfect’ architecture.

A start-up which is creating a SaaS solution for small businesses could benefit from utilising shared infrastructure as this minimises effort.

Where a business has stringent separation, legal and/or contractual needs an enterprise may require private database(s) and/or infrastructure.

In some cases, SaaS companies choose to use shared and private infrastructure. 

Common users are provided with shared infrastructure whereas specific enterprise users are given private infrastructure.

It is key that the chosen architecture can accommodate a business’ needs, and that this can be achieved without significant changes to the software.

Common Database Models for Multi-Tenant SaaS Architecture

multi-tenant SaaS architecture design
multi-tenant SaaS architecture design

Database design is one of the most important decisions in multi-tenant SaaS development.

The database defines how customer data is stored, accessed, secured and administered.

Typical options for this are ‘shared’, ‘per-schema’ and ‘per-database’.

1. Shared Database with a Shared Schema

In this model, every tenant uses the same database and the same set of tables.

A ‘tenant id’ (often abbreviated to just tenant_id) allows data relating to each different customer to be separated.

For example, an application may maintain a projects table:

project_idtenant_idproject_name
101tenant_AWebsite Redesign
102tenant_BMobile Application
103tenant_CCRM Implementation

Each record belongs to a specific tenant.

If users wish to see data about projects then data is returned for their permitted tenant(s).

Advantages:

  • Lower infrastructure overhead.
  • Database centralisation.
  • Easier schema updates.
  • Suitable for applications with many smaller customers.

Limitations:

  • Tenant isolation depends on strong authorization and database controls.
  • Concurrent intensive tenant data usage can effect other tenants.
  • Each tenant will also need separate backup and recovery arrangements.
  • Tenant-specific database customization is difficult.

Row Level Security can be used to define database-level data access controls.

PostgreSQL provides functionality which allows for defining row-Level Security policies and so controlling what data can be accessed by a database or application role.

Official documentation: https://www.postgresql.org/docs/current/ddl-rowsecurity.html

This model can be appropriate for early-stage SaaS products when implemented with strong tenant isolation.

2. Schema-Per-Tenant Architecture

In this approach, customers share one database instance but receive separate database schemas.

A schema groups together database elements such as tables, indexes and views.

For example:

  • tenant_a.projects
  • tenant_b.projects
  • tenant_c.projects

The application identifies the correct tenant schema when processing a request.

Advantages:

  • Greater logical separation of database objects.
  • Tenant-specific database organization.
  • Facilitates identification of data relating to individuals.
  • Some flexibility for tenant-specific database configurations.

Limitations:

  • Database migrations become more complicated.
  • Schema’s should be managed automatically.
  • Managing numerous schemas adds to workload.
  • Furthermore, there is added care needed when linking to and querying schemas.

This method could work well for SaaS offerings which require greater segmentation than a non-segmented table structure but without having an entirely separate database per customer.

3. Database-Per-Tenant Architecture

In this model, each customer receives a dedicated database.

Whilst potentially reusing the code and application services, customer data is held in a different location.

For example:

  • Company A uses Database A.
  • Company B uses Database B.
  • Company C uses Database C.

The application identifies the tenant and connects to its assigned database.

Advantages:

  • Stronger database-level separation.
  • Independent backup and restoration.
  • Improves database management.
  • Enhances ability to meet differing data location and performance needs for customers.

Limitations:

  • Database provisioning requires automation.
  • Further data sources can also be monitored.
  • Cross-tenant synchronisation is often required.
  • As a business expands there may also be an associated rise in infrastructure expenditure.

Such a set-up can be particularly applicable to large scale SaaS offerings which need additional control over, and isolation of, data.

Comparing the Three Database Models

FactorShared schemaSchema per tenantDatabase per tenant
Database countOneOneMultiple
Data separationTenant ID and controlsSeparate schemasSeparate databases
Infrastructure overheadLowerModerateHigher
Migration managementCentralizedPer schemaPer database
Tenant customizationLimitedModerateGreater
Operational complexityLower initiallyModerateHigher

Note that these are relative architectural considerations and do not provide definite cost or performance outcomes.

AWS and Microsoft provide additional architectural guidance for evaluating these approaches:

Essential Components of a Multi-Tenant SaaS Application

Database isolation alone does not create a complete multi-tenant application.

There are multiple parts to a secure application.

1. Tenant Identification

The application must identify the correct tenant before processing customer-specific operations.

Common approaches include:

  • Tenant identifiers stored in authenticated user claims.
  • Organization IDs associated with user accounts.
  • Tenant-specific subdomains.
  • Tenant identifiers maintained in application sessions.

For example, a user accessing company-a.example.com may be associated with Company A.

However, even if a sub domain or query string is provided, this does not necessarily mean that a user is authorised.

The back-end of an application must verify both a users identity and their level of access.

2. Authentication and Authorization

Authentication establishes who the user is.

Users have certain levels of access.

Multi-tenant SaaS services need to be able to define access at an individual and organisational level.

For example:

  • The organisation owner can access and edit financial and account information.
  • Administrators can edit staff and access details.
  • A project manager can modify assigned projects.
  • Users can be given access to certain functions and information.

Access needs to be validated in the right tenant.

It should also be possible to move easily between different organisations that a user is part of. When doing so, they should not inadvertently continue to have access that relates to their previously affiliated organisation.

3. Tenant-Aware Database Access

Every tenant-specific database operation must respect the active tenant context.

For example, when a user asks to retrieve customer data, the app must ensure that the user is a tenant of that data prior to providing it.

Useful implementation practices include:

  • Applying tenant identifiers consistently to relevant database records.
  • Enforcing Row-Level Security where supported.
  • Restricting database permissions.
  • Confirming that a user is part of a particular tenant.
  • Checking database queries for multi-tenancy issues.

Do not solely enforce controls at the front-end.

A person should not be permitted to view data belonging to another company merely by changing an ID within a URL or API call.

4. Tenant Configuration Management

Different customers may need different application settings.

A business may wish to define new user roles and/or tailor alert types and application links.

Centralise and manage ‘tenant’ specific settings within a configuration management solution.

Examples include:

  • Organization name and branding.
  • Enabled application modules.
  • User permissions.
  • Subscription limits.
  • Notification settings.
  • Integration credentials.
  • Data retention preferences.

Before implementing configuration settings they should be reviewed and approved.

This then enables the platform to adapt for different customers without adding unneeded application complexity.

How to Design Secure API Integrations in a Multi-Tenant SaaS Application

SaaS tenant isolation
SaaS tenant isolation

API integration becomes more complicated when one SaaS application serves multiple customers.

An integration may require different authentication details, rights and mapping for different organisations.

For example, there is a SaaS application which integrates with a CRM.

Both organisation A and B integrate their own CRM accounts. They both utilise the same integration service.

Therefore the integration must recognise which tenant is being referenced, and apply the relevant authentication details to that tenant.

1. Maintain Tenant Context Across API Requests

Each call to an API should include an appropriate tenant context.

Where possible, the application should determine the tenant based upon the authenticated identity or secure back-end context and not just pass through a tenant identifier that has been provided by the client.

A simplified workflow looks like this:

  1. The user initiates an integration request.
  2. User authentication is performed. 
  3. An authorised tenant is recognised by the application. 
  4. The integration service retrieves that tenant’s configuration.
  5. The service obtains the appropriate API credentials.
  6. The external API request is executed.
  7. The response is associated with the correct tenant.

So that one organisation’s integration details are not mistakenly utilised by another.

2. Store API Credentials Separately for Each Tenant

Third-party services often require API keys, OAuth tokens, or other credentials.

A multi-tenancy application should hold distinct integration details for each organisation.

For example:

TenantConnected serviceCredential reference
Company ACRMCredential A
Company BCRMCredential B
Company CAccountingCredential C

The actual secrets should be stored securely, preferably using a dedicated secrets-management system or encrypted credential storage.

Never store API keys in client-side code, URLs, browsers or in your app.

Think also about tokens, re-fuelling tokens, and how to cancel them. Alongside this, consider updating user permissions.

3. Apply Tenant-Level API Permissions

Not every tenant should have access to every integration feature.

For instance, one business may be permitted to sync customer relationships management (CRM) data and another may just be able to generate reports.

The integration service should verify:

  • Whether the tenant has access to the integration.
  • Whether the connected account is valid.
  • Whether the user has permission to initiate the operation.
  • Whether the requested data belongs to the active tenant.
  • And that the integration is within the tenant’s usage entitlements.

So the integration continues to conform to the applications authorisation scheme.

4. Separate Integration Data by Tenant

External API responses should be associated with the correct tenant before being stored.

For example if a CRM integration is utilised to import 500 customers,

the application must ensure that the integration has been authorised and then attach the correct tenant reference to each of the imported customers.

The same principle applies to:

  • Accounting records.
  • Payment transactions.
  • Marketing contacts.
  • Inventory information.
  • Support tickets.
  • External project data.

A useful design is to maintain a separate integration configuration record for each tenant and connect imported data to that tenant through validated relationships.

5. Implement Tenant-Level Rate Limits

Many third party APIs also apply a request rate limit.

Should all customers be integrated via the same service then an especially high volume tenant may take up a significant proportion of the API resource.

To avoid this, introduce a tenant rate limit function.

For example, the platform can track:

  • API requests per tenant.
  • Requests per connected account.
  • Failed API calls.
  • Daily synchronization volume.
  • Retry attempts.
  • External API response times.

Your service’s throttle settings should take into consideration both the third party’s and your own SaaS’ throttling rules.

This ensures that one customer does not make inappropriate use of another’s service resource.

Webhooks and Event-Driven Architecture in Multi-Tenant SaaS

Webhooks allow external applications to notify your SaaS platform when an event occurs.

For instance, a payment service can issue a webhook for a successful subscription payment. Similarly, a CRM can produce one for an update to a customer.

Within a multi-tenant application, the webhook receiver must be able to recognise which tenant the event relates to.

A practical workflow includes:

  1. Receive the webhook request.
  2. Verify the provider’s signature using the appropriate signing secret.
  3. External account / app integration to which the request relates.
  4. Resolve the associated tenant through trusted server-side records.
  5. Confirm event and data.
  6. Check whether the event has already been processed.
  7. Process the event within the correct tenant context.
  8. Record the processing result.

Never assume that a webhook’s tenant_id accurately reflects the external account that it is related to. Always verify this separately.

Prevent Duplicate Webhook Processing

External providers may retry webhook delivery when they do not receive a successful response.

Multiple payments or updates to customer details could both result from the same event if there is no deduplication process.

Use an idempotency strategy based on the provider’s event identifier or another reliable unique event key.

Maintain information on stock so that multiple deliveries can be managed.

Further information on event delivery and system integration can be found in BKABHI’s documentation on integrating webhooks and building an event driven architecture.

Real-Time Data Synchronization Across Multiple Tenants

Data synchronization introduces another challenge.

A multi-tenant SaaS solution can integrate with multiple external systems. It must be able to update related data for the right owner(s).

A company will often integrate their CRM, accounts and helpdesk solutions.

If a customers details are amended within a companys CRM then the application may need to also amend the relevant data in another integrated system.

The synchronization process should maintain:

  • Tenant ownership.
  • External record identifiers.
  • Data mapping rules.
  • Synchronization timestamps.
  • Processing status.
  • Error information.
  • Retry history.

Cross-tenant data synchronization can also lead to issues.

Businesses can also have data in external systems that has similar identifiers, but for different tenants.

Two organizations may have records with similar identifiers in different external systems.

The application should maintain a relationship between the tenant, integration account, external record ID, and internal record ID.

This ensures the right organisations data is updated.

For further information on how to implement this please refer to BKABHI’s documentation on synchronising data in real time between applications.

Security Considerations for Multi-Tenant SaaS Architecture

Security should be considered throughout the architecture rather than added after development.

Important areas include:

Data Isolation

Ensure users cannot retrieve or modify records belonging to another tenant.

Implement database and back-end security features together with automated security testing.

Encryption

Protect sensitive information during transmission using HTTPS/TLS.

Encrypt information and login details appropriately.

Role-Based Access Control

Implement permissions based on user roles, tenant membership, and resource ownership.

Not all users who are able to log-in should automatically be granted access to all the items available to an organisation.

Secure Background Jobs

Background jobs, scheduled tasks, and asynchronous workers must preserve tenant context.

A job must not inadvertently work on data for more than one tenant due to incorrect setup of the job’s execution environment.

Audit Logging

Record important operations, including:

  • Login and authentication events.
  • Permission changes.
  • Integration connections.
  • Credential updates.
  • Data exports.
  • Administrative actions.
  • Failed authorization attempts.

Information about which tenant and user is involved should be included in audit trails but without disclosing excessive detail.

Backup and Recovery

Create backup and restoration procedures that account for the selected tenancy model.

Ensure that a single customer can be restored without adversely impacting other customers.

The recovery approach should reflect the availability and recovery needs of the application.

Common Multi-Tenant Architecture Mistakes to Avoid

Several implementation mistakes can create security and maintenance problems.

1. Tenant level UI controls

Whilst UI controls are good for users, they do not provide security. Validate access on the backend.

2. Forgetting tenant context in background jobs

Asynchronous processing must receive and validate tenant context just like normal API requests.

3. Inter-organisation sharing of API keys

Implement organisation specific integration keys. Confirm that an organisation owns a key prior to making external calls.

4. Creating separate database tables for every tenant

This approach can become difficult to maintain as the number of customers grows. A shared schema with tenant identifiers or an appropriate database-per-tenant model is generally easier to manage.

5. Disregard issues with neighbours

Within a shared environment, tenants will need to be able to compete. Usage should be analysed and quotas implemented if required.

6. Allowing unrestricted tenant customization

Store customer preferences and configurations separately from core application logic. Avoid uncontrolled tenant-specific code changes.

7. Failure to analyse tenant data 

Whilst there may be an overarching analytics screen, tenant specific issues can still occur. Analyse tenant specific data regarding integration, usage and performance.

How to Choose the Right Multi-Tenant SaaS Architecture

Multi-tenant database architecture
Multi-tenant database architecture

There is no universal architecture that works for every SaaS product.

The choice should be informed by the nature of the customer base, plus security, integration and capacity needs along with anticipated load levels.

Before selecting an architecture, consider the following questions:

  • How many customers do you expect to support?
  • How much data will each tenant generate?
  • Do customers require dedicated databases?
  • Are there contractual or regulatory isolation requirements?
  • Will customers connect their own third-party applications?
  • Does each tenant need separate API credentials?
  • Will different customers have different subscription limits?
  • Can your team automate database provisioning and migrations?
  • Can your solution allow for some customers to be hosted on dedicated environments?

Generally, during initial product development, a multi-tenant set-up with good tenant segregation should suffice.

As a B2B product develops it may be better to implement either or both of; a multi-schema and/or multi-tenancy solution.

Where customers have specific needs for their environment then a per-tenant database or dedicated hosting could also be required.

An optimal choice is therefore one which not only fulfils present needs but can also easily adapt to new ones.

Multi-Tenant SaaS Architecture Design Checklist

Before launching a multi-tenant application, review these implementation areas.

Tenant management

  • Every organization has a unique tenant identifier.
  • User accounts are associated with authorized tenants.
  • Tenant switching validates membership and permissions.
  • Tenant-specific settings are stored separately.

Database architecture

  • The database isolation model is documented.
  • Tenant ownership is enforced for relevant records.
  • Database-level security controls are configured where appropriate.
  • Database migrations are tested.
  • Backup and restoration procedures are documented.

API integration

  • Each tenant has separately managed integration credentials.
  • Context is maintained for APIs.
  • Integration permissions are validated.
  • Tenant-level rate limits are implemented where needed.
  • Webhook signatures are verified.
  • Duplicate event processing is handled.

Security

  • Backend authorization is enforced.
  • Sensitive credentials are stored securely.
  • Context is also maintained for background processes.
  • Key tenant events are also logged.
  • Cross-tenant access tests are included in the testing process.

Performance and monitoring

  • Tenant-level resource consumption is monitored.
  • API errors are tracked by tenant.
  • Noisy-neighbor risks are evaluated.
  • Usage limits are defined.
  • Scaling and migration strategies are documented.

Conclusion

Whilst multi-tenancy is about enabling several clients to access your software, there are further elements which must be carefully considered. This includes tenant recognition, database separation and management, along with security, API and webhooks and analytics.

Decisions relating to multi-tenancy should be made based on real client needs and not simply anticipated growth. The method of separation – be it shared, schema or individual databases – should therefore align with these needs.

As with databases, APIs and webhooks must also be multi-tenant aware. All external requests, synchronisation and processes must continue to relate to the relevant business.

Entrepreneurs and developers will want to create a secure, well-integrated and easily scalable system for their SaaS offering.

Before designing your database and software, clearly set out the multi-tenancy and integration needs for your SaaS offering. Making such decisions at an early stage can greatly assist both development and ongoing system management.

About the Author

Jeevesh Tripathi
Email: jeevesh@bkabhi.com

Jeevesh Tripathi writes research-based content about software development, SaaS architecture, AI, and technology. His articles focus on practical explanations, evidence-based evaluation, and helping founders and development teams understand technical decisions.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top