SaaS Tenant Data Isolation: Shared or Separate Databases?
Choose between shared tables, separate schemas and separate databases for SaaS tenant data isolation, then prove the boundary with tests that fail closed.

SaaS tenant data isolation is the set of database controls that stop one customer's records from being read or changed by another. There are four common designs: shared tables with a tenant key and row-level security, a separate schema per tenant, a separate database per tenant, or a hybrid that uses different designs for different tiers or data classes. None is safe by default. Each holds only if it is enforced at the data layer, used through the right database role and tested on every change.
This guide is for development leads and product owners choosing a storage design. Our related guide on SaaS security explains why buyers ask about isolation first; this article covers how the boundary is built and proven in the database.
Key Takeaways
- Pick a database design for each data class and customer tier. A hybrid of shared and dedicated storage is normal.
- Shared tables are the cheapest to run but depend on a database policy covering every tenant-owned table and a request role that cannot bypass it.
- Application filters in the ORM are a second line of defence, not the boundary. Raw SQL and bulk jobs can skip them.
- Backups, restores and offboarding are easy places for isolation to break, so test them as carefully as queries.
- Accept the design when automated tests prove cross-tenant access is denied for every table, through the real application role and connection pool.
The Four SaaS Tenant Data Isolation Designs Compared
The OWASP Multi-Tenant Security Cheat Sheet describes each design by the boundary it provides and the conditions it depends on. The summary below follows that framing.
- Shared tables with row-level security - Boundary: a policy on each row; Depends on: every tenant-owned table carrying a tenant association and policy, a constrained request role and negative tests; Running cost: lowest.
- Schema per tenant - Boundary: namespace and database role; Depends on: disciplined grants, correct search_path handling and migrations applied to every schema; Running cost: moderate, rising with tenant count.
- Database per tenant - Boundary: database and credentials; Depends on: separate credentials, network access, admin paths and backups; Running cost: highest.
- Hybrid - Boundary: varies by tier or data class; Depends on: documenting and testing the boundary used for each data class; Running cost: depends on the mix.
The wider question of which parts of the system to share, such as compute, queues and caches, belongs to the overall design. Our guide to multi-tenant SaaS architecture and isolation choices covers that layer, and our related guide on SaaS tech stack decisions explains why the tenancy model is expensive to reverse.
Decision Inputs for Choosing a Database Design
- Contract and regulatory terms. A customer that requires its own database, region or encryption keys settles the question for that tenant.
- Tenant count. Thousands of small tenants make per-tenant databases or schemas costly to migrate and monitor.
- Data volume spread. One tenant holding most of the data can dominate shared indexes and maintenance windows.
- Restore and export needs. If customers expect a single-tenant restore on request, design for it now.
- Cross-tenant reporting. Platform analytics across all tenants is simple with shared tables and harder with separate databases.
- Release cadence. Frequent schema changes favour fewer databases to migrate.
How Shared Tables Fail, and How to Stop It
Shared tables with PostgreSQL row-level security are a sound design, but they fail in specific, well-documented ways. Each has a direct control.
The request role bypasses the policy
PostgreSQL's row security documentation states that superusers and roles with the BYPASSRLS attribute always bypass row security. FORCE ROW LEVEL SECURITY applies policies to the table owner, but not to those roles. Connect normal application traffic with a least-privileged role, and keep privileged connections for migrations and authorised admin jobs.
Tenant context leaks across pooled connections
Policies often read the tenant from a session setting. OWASP notes that a normal SET persists for the session, so a pooled connection reused without a reset can carry one request's tenant into the next. Set the tenant per transaction with SET LOCAL or set_config with its local flag, re-establish it on every transaction, and fail closed when it is missing.
Raw queries skip the ORM filter
ORM-level tenant filters help, but OWASP points out that they may not cover raw SQL, bulk statements or writes. Keep the database policy as the final boundary and add an explicit tenant predicate to any raw query.
New tables arrive without policies
A table added next quarter can ship without row-level security. Derive the list of tenant-owned tables from the schema and fail the build when a table has no classification or policy.
Separate Schemas and Databases Have Their Own Failure Modes
Separate schemas and databases reduce the blast radius of a query bug, but they add operational risks.
- Migration drift. A migration that fails on a few of hundreds of schemas leaves tenants on different versions. Track the schema version per tenant and alert on mismatches.
- Connection limits. Many databases or schemas can exhaust connection pools. Plan pooling per tenant group, not per tenant.
- Credential sprawl. Per-tenant credentials need rotation and storage. Isolation is only as strong as the place those secrets live.
- Uneven monitoring. A slow tenant database is easy to miss when it is one of hundreds. Report health per tenant.
Backups, Restores and Offboarding
A shared backup can hold data from many tenants. Microsoft's multitenant storage guidance, which OWASP cites, describes restoring into a separate resource and selectively recovering the target tenant's data. OWASP also warns against restoring a shared snapshot over live data to recover one tenant.
Offboarding needs the same care. Apply the retention policy to every place a tenant's data lives, including caches, file storage, replicas, exports and backups. Watch path matching in object storage: OWASP gives the example that the prefix tenants/acme would also match tenants/acme-west, so delete by an exact boundary such as tenants/acme/.
White-label products add a partner level above tenants, and that boundary needs the same tests. Our guide to white-label SaaS architecture covers the partner layer.
A SaaS Tenant Data Isolation Checklist for Acceptance
These pass conditions follow OWASP's verification advice. Run them in CI and in a production-like environment, through the same role, connection path and pooling mode as the application.
- For every tenant-owned table, derived from the schema, cross-tenant reads and writes are denied and same-tenant operations succeed.
- A configuration test fails if the request role is a superuser or has BYPASSRLS, checked against the live role in pg_roles.
- Two tenants' requests over reused pooled connections never see each other's tenant context.
- A restore drill recovers one tenant from backup into a separate resource, and the other tenant's records are absent.
- An offboarding drill removes a test tenant's data from every store under the retention policy, and an exact-prefix check confirms no neighbouring tenant was touched.
- Any new table without a tenant classification fails the build.
Related Resources
- Industry business systems from 9Byte
- SaaS security: what customers ask before they sign
- Multi-tenant SaaS architecture: isolation choices
- White-label SaaS architecture and brand boundaries
- OWASP Multi-Tenant Security Cheat Sheet
- PostgreSQL row security policies
- Microsoft: storage and data in multitenant solutions
Common Questions About SaaS Tenant Data Isolation
1. Is row-level security enough for tenant isolation?
It can be the main boundary when every tenant-owned table has a policy, the application role cannot bypass it and tenant context is set per transaction. Add application checks as a second layer and test cross-tenant denial for every table.
2. When should each tenant get its own database?
When a contract or regulation requires it, when a tenant needs its own region or keys, or when its size and load justify the extra running cost. Many products keep most tenants shared and give dedicated databases to an enterprise tier.
3. Is schema-per-tenant a good compromise?
It gives a clearer namespace boundary than shared tables at lower cost than separate databases. The trade-off is migration and grant management across every schema, which grows with tenant count.
4. How do you restore one tenant's data from a shared database?
Restore the backup into a separate resource, then copy only the target tenant's records back after checking ownership. Do not restore a shared snapshot over live data, because it would roll back every other tenant too.
5. Can you move a tenant to its own database later?
Yes, if every record carries a reliable tenant association and the application routes connections by tenant. Plan the export, cut-over and verification steps, and test them before a customer asks.
Prove the Boundary Before a Customer Tests It
SaaS tenant data isolation depends less on which design you pick than on how it is enforced and tested. Match the design to each data class, close the role, pooling and raw-query gaps, and hold acceptance until the cross-tenant, restore and offboarding tests pass. For systems where data separation and uptime both carry contractual weight, our industry business systems page outlines how 9Byte builds, integrates and maintains them.


