Multi-Tenant SaaS Architecture: Models, Trade-offs and Security
· Technology · 14 min read · By Prashant Kumar
Shared tables, schema per tenant or database per tenant? How multi-tenant SaaS works, how to stop cross-tenant leaks, tame noisy neighbours, meter usage and meet data residency needs.
Multi-tenant SaaS architecture means one running product serves many customer organisations, called tenants, from shared infrastructure, while each tenant's users, data and settings stay walled off. The core decision is how much to share: one database with a tenant ID on every row, a schema per tenant, or a database per tenant. A common path is to start shared and give larger or regulated customers more isolation as they sign.
What is multi-tenant SaaS architecture, and why does SaaS need it?
In a business-to-business product, a tenant is usually one customer company, and its employees are its users. The mapping is not always one-to-one: a large customer may want separate tenants for divisions or countries, or one for testing (Microsoft, tenancy models). Settle this first, because it decides what your tenant ID identifies.
The reason is economics. With a dedicated stack per customer, cost grows roughly in step with customer count and every update must reach every copy. Sharing means one fleet, one release, and onboarding by creating a record, not servers.
Salesforce is a well-known example: its architects describe one shared database and schema for all customer orgs, with records tagged by an org ID (Salesforce Architects). Still shaping the product? Read our guide on how to build a SaaS product.
Single tenant vs multi tenant at a glance
| Aspect | Single-tenant | Multi-tenant | Hybrid |
|---|---|---|---|
| Data isolation | Physical: own servers or databases | Logical: enforced by code and database rules | Physical for some tenants, logical for the rest |
| Cost per customer | Highest | Lowest | In between |
| Updates | Each copy separately | One release for everyone | Shared fleet plus a few dedicated deployments |
| Noisy neighbour risk | Low | Needs quotas and monitoring | Low for dedicated tenants |
| Typical fit | A few large or regulated clients | Many small and mid-size customers | Products that sell to both |
If you are unsure which model suits your first customers, book a free architecture consultation and tell us who you sell to.
A multi-tenant SaaS architecture diagram, layer by layer
AWS names four building blocks: tenant identity, data isolation, compute and runtime, and operations, with tenant context carried through every log, metric and billing event (AWS building blocks). A request flows like this:
User opens acme.yourapp.com
|
[1] Resolve the tenant
(subdomain, path or token claim)
|
[2] Sign in: token carries
user ID + tenant ID + role
|
[3] APIs and services
tenant checks, rate limits
|
[4] Data layer
shared tables | schema | own DB
|
[5] Logs, metrics, usage meter
tagged with tenant ID
Control plane, alongside:
onboarding, plans, billing,
tenant-to-deployment map, offboarding
The control plane is the part founders forget: the admin system that creates tenants, tracks plans and deployments, and runs upgrades.
Multi-tenant database design: the three main models
AWS describes three multi-tenant SaaS architecture patterns: pool (shared resources), silo (dedicated resources) and bridge (a mix). Even siloed tenants share one identity, onboarding and operations system (AWS SaaS Lens). For a relational database, that gives three options plus a hybrid.
1. Shared database, shared schema
All tenants share the same tables, and every tenant-owned row carries a tenant_id. It is the cheapest and simplest to run: one database to back up, patch and migrate. Microsoft lists the drawbacks (Microsoft data guidance):
- One database eventually hits size or throughput limits.
- Busy tenants can slow everyone else.
- Tenant-specific backup, location or encryption needs are hard to meet.
- Restoring one tenant can mean restoring a copy of the database and extracting their rows.
The biggest risk is human: one query that forgets the tenant filter leaks data.
When one database grows too big or too busy, Microsoft points to sharding: several databases, each holding a group of tenants, plus a tenant-to-shard map that routes each request. It also suggests packaging the whole stack as a deployment stamp, even with a shared or sharded database inside, so you can deploy another copy, say in a new region.
2. Schema per tenant
One database server, with a separate schema (a named set of tables) per tenant. AWS treats this as a middle ground between a pool and fully dedicated infrastructure. Exporting or deleting a tenant is cleaner, but every migration runs once per tenant and each schema's version must be tracked.
In MySQL and MariaDB, CREATE SCHEMA is simply another name for CREATE DATABASE (MySQL docs, MariaDB docs), so there "schema per tenant" means one database per tenant on a shared server: separate tables, but shared CPU, memory and disk.
3. Database per tenant
Each tenant has its own database behind a shared application tier. Isolation is strongest: one tenant can be restored, moved to another region or encrypted with its own key, and a heavy tenant mostly slows only itself. The price is more databases to run. Microsoft warns that managing them by hand becomes overwhelming, so automate provisioning and migrations, and consider pooled capacity such as Azure SQL elastic pools.
4. Hybrid or tiered tenancy
Mature products often mix models: shared tables for standard plans, a dedicated database or deployment for enterprise customers who pay more. Microsoft calls this vertical partitioning: the codebase must support both modes, and if tenants can move between them you need a repeatable, safe way to migrate them.
| Factor | Shared schema | Schema per tenant | Database per tenant |
|---|---|---|---|
| Isolation | Tenant ID plus rules | Separate schema | Separate database |
| Running cost per tenant | Lowest | Low to medium | Highest |
| Schema migrations | Run once | Once per tenant | Once per tenant database |
| Restoring one tenant | Hard: restore a copy, extract rows | Easier | Easiest |
| Tenant-specific region or key | Difficult | Difficult | Possible |
| Noisy neighbour exposure | Highest | High (same server) | Lower at the data layer |
| Usually fits | Self-serve products, early stage | Moderate tenant counts | Enterprise or regulated tenants |
Whichever you pick, Microsoft lists patterns to avoid: per-tenant tables in one database, columns added for one tenant, and hand-applied schema changes. Deploy schema changes through a pipeline, record each tenant's schema version, and keep each release working with the previous schema too, because tenant databases will not all upgrade at once. Our database services cover this.
Not sure which model fits? Share your expected tenant count and your largest customer's security requirements, and we will suggest a tenancy model and a growth path for it.
Tenant identity, roles and access control
Multi-tenancy starts at sign-in. The AWS SaaS Lens binds every user to a tenant and puts the tenant in the user's token as a custom claim, so services need no extra lookup (AWS SaaS Lens, identity).
The app also resolves each request's tenant from a subdomain such as acme.yourapp.com, a path, a token claim or an API key. Microsoft stresses that a tenant identifier in the request does not grant access: the app must still check each request is authorised for that tenant (Microsoft, request mapping).
- Memberships, not one tenant column on users. Accountants and agencies work in several customer accounts.
- Tenant-scoped roles. Admin in tenant A means nothing in tenant B. Audit support access.
- Per-tenant sign-in rules. Enterprise customers may want single sign-on through their own identity provider.
How do you prevent data leaks between tenants?
An easy point to miss: an authenticated, authorised user can still reach another tenant's resources unless isolation is applied separately (AWS SaaS Architecture Fundamentals, an archived whitepaper). AWS's current SaaS Lens calls any crossing of that boundary "a significant and potentially unrecoverable event" (AWS SaaS Lens, tenant isolation).
In APIs, the usual failure is broken object level authorization, first in OWASP's API Security Top 10 2023: an API returns a record by ID without checking the caller may see it, which in SaaS means a cross-tenant leak. Layer your defences:
- Take the tenant ID from the verified token, never from a form field or request body.
- Route all data access through one tenant-aware layer that adds the tenant filter automatically.
- Add a database safety net. PostgreSQL row-level security can refuse other tenants' rows, but superusers, BYPASSRLS roles and table owners (unless FORCE ROW LEVEL SECURITY is set) skip it, so connect the app as an ordinary role (PostgreSQL docs). Microsoft calls it complex to test, so test it like code.
- Scope everything else: cache keys, file paths, search indexes, queues, jobs and exports.
- Test for leaks automatically. As tenant A, try to read, change and delete tenant B's records through every endpoint; OWASP advises not deploying changes that fail such tests.
-- PostgreSQL safety net for a shared "orders" table
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
ALTER TABLE orders FORCE ROW LEVEL SECURITY;
CREATE POLICY orders_by_tenant ON orders
USING (tenant_id = current_setting('app.tenant_id')::uuid)
WITH CHECK (tenant_id = current_setting('app.tenant_id')::uuid);
-- In each transaction the app runs:
-- SELECT set_config('app.tenant_id', $1, true);
-- $1 = tenant ID from the verified token
-- true = applies to this transaction only
Passing the tenant ID as a parameter to set_config keeps it out of the SQL text. If the setting is missing, the query fails instead of leaking rows.
Performance and noisy neighbours
On shared infrastructure, one tenant's month-end report or bulk import can slow everyone. Microsoft says this risk can be managed, not removed (Microsoft, noisy neighbor):
- Measure resource use per tenant and alert on spikes.
- Apply per-tenant quotas and rate limits, and publish them.
- Run heavy, non-urgent work such as exports off-peak in background queues.
- Cap expensive queries with row or time limits.
- Move a heavy tenant to another shard, its own database or its own deployment.
The same pool-or-silo choice applies to compute. In a pooled design every tenant shares one fleet of app servers and workers, so give each tenant a fair share of the job queue: one tenant's bulk import should not hold up everyone's invoices. A tenant who pays for isolation can get dedicated workers under the same control plane; AWS describes options from per-tenant concurrency caps to dedicated compute.
Tie limits to plans, and make per-tenant dashboards part of your DevOps and monitoring setup.
Per-tenant settings, plans and billing
Customers will ask for different workflows, fields and branding. Microsoft advises against forking code or infrastructure per tenant; use feature flags, tenant configuration and a custom-fields table. A plan then becomes a set of entitlements: features switched on, limits applied.
Billing depends on measurement. Microsoft advises measuring each tenant's consumption to know its cost to serve and what to charge, and warns that sampled monitoring data is not accurate enough for billing (Microsoft, measure consumption). Per-seat plans need user counts, usage-based plans need auditable usage events, and feature tiers need entitlements (Microsoft, pricing models).
Keep the subscription's commercial state (active, grace period, suspended, cancelled) separate from the tenant's technical state. Microsoft advises against deleting tenant data the moment a subscription is suspended or cancelled, unless a contract or law requires deletion: deactivate first, keep needed billing and audit records, and delete after the agreed retention period (Microsoft, tenant life cycle).
Agree that period in your customer contracts. Section 8(7) of India's Digital Personal Data Protection Act, 2023 requires personal data to be erased once consent is withdrawn or its purpose is no longer served, unless a law requires keeping it, and the business must make its processors, which can include its SaaS provider, erase it too.
Backups, restores and data residency
Ask early: if one customer deletes a month of records by mistake, how do you return only their data? In a shared database you may need to restore a copy and extract their rows, so script and rehearse that now. Promise only the recovery your architecture can deliver.
Data location can also force isolation. Section 16 of the DPDP Act lets the Central Government restrict personal data transfers to notified countries and keeps stricter laws in force, such as the RBI's April 2018 circular requiring payment system providers to store the entire data relating to their payment systems only in India.
Selling to banks, payment firms or large enterprises? Store a region on every tenant record and be ready to run a stack in an Indian cloud region. Our guide to DPDP Act compliance for apps covers the wider obligations.
Moving from single-tenant to multi-tenant
Software built for one client often attracts others, until each customer runs a slightly different copy. A practical conversion order:
- Define the tenant, and create a tenants table and a tenant-to-deployment map.
- Add a mandatory, indexed tenant ID to every tenant-owned table and backfill it.
- Put all data access behind a tenant-aware layer, then add database rules as a backstop.
- Replace customer-specific code branches with settings and feature flags.
- Rework sign-in around memberships, with the tenant ID in the token.
- Make caches, files, jobs and logs tenant-aware, and add cross-tenant tests.
- Move customers in one at a time, keeping each old copy until its move is verified. This follows the incremental idea Martin Fowler describes as the strangler fig: replace the old system step by step, not in one big bang.
Decision checklist: choosing your tenancy model
- Who is a tenant: a company, a branch, a family or one person? This fixes what your tenant ID means.
- How many tenants in two to three years, and how big is the largest? Many small tenants point to shared tables; a few huge ones may justify their own databases.
- Will any customer contractually require dedicated infrastructure, their own keys or data in a specific country? If yes, plan a dedicated tier from day one.
- Do some customers need different backup or uptime promises? If yes, group them on separate databases or stamps.
- Will tenants customise fields and workflows? If yes, design a custom-fields table and feature flags now.
- How much provisioning and migration can your team automate? If little, hold off on a database per tenant.
For early-stage B2B products, a sensible default is shared tables with the tenant ID enforced in code and database, per-tenant metrics, and a tenant-to-deployment map so a premium customer can later move to their own database.
Frequently asked questions
What is multi-tenant architecture in simple words?
One application shared by many customers, like flats in one building: each flat (a customer's data and settings) is locked, while the structure and wiring (servers, code, databases) are shared.
What are the disadvantages of multi-tenant architecture?
An isolation bug can expose many customers at once, a busy tenant can slow others, and one faulty shared component can affect every tenant. Per-tenant restores, keys and data locations are also harder in a shared database. Good design and testing reduce these risks but do not remove them.
Is multi-tenant SaaS secure enough for enterprise customers?
It can be. Security depends on how isolation is built and tested, not on the label. A dedicated database or deployment as a higher tier answers the strictest buyers.
Which database is best for a multi-tenant SaaS?
The tenancy model matters more than the brand. PostgreSQL offers schemas and row-level security, and Azure SQL Database has row-level security too. Pick an engine your team knows well.
How do AWS and Azure describe multi-tenant SaaS?
AWS uses silo (dedicated resources), pool (shared resources) and bridge (a mix). Microsoft's Azure guidance covers the same range with shared, sharded and per-tenant databases and deployment stamps. The ideas apply on any cloud.
Conclusion
Good multi-tenant SaaS architecture comes down to a few early decisions: what a tenant is, how much you share, and where isolation is enforced. Start simple, enforce it in more than one layer, and keep a path open to dedicated resources.
Appsgain's SaaS platform development work covers multi-tenant architecture, subscription billing and self-serve onboarding, and we build and run our own products, such as Snapkio, a WhatsApp Business platform. Designing a new SaaS or untangling a copy-per-customer setup? Discuss your SaaS architecture with us: send your customer profile and feature list, and we will map out a tenancy model.
Tags: SaaS Architecture, Multi-Tenancy, Database Design, Data Isolation, SaaS Development
