Multi-Tenant SaaS Architecture: How to Choose a Tenancy Model
Compare the three main multi-tenancy models for SaaS, a shared database, schema per tenant, and database per tenant, with trade-offs for isolation, cost, scaling, and compliance, plus practical tips for PostgreSQL.
By Cinnamon Digital ·
Most SaaS products should start with a shared database where every tenant-owned row carries a tenant ID, enforced by row-level security. Separate schemas or databases per tenant offer stronger isolation, but at a higher operational cost that early-stage products rarely need. The right choice depends on your customers' isolation requirements, scale, and the size of your team.
The three main models
1. Shared database, shared schema
All tenants share the same tables. Every tenant-owned table has a tenant_id column, and every query filters by it.
- Pros: Simplest to build and operate, lowest cost, one migration updates everyone, and easy cross-tenant reporting for your own analytics.
- Cons: A missed filter can expose data between tenants, one heavy tenant can slow others, and some enterprise or regulated customers may require stronger separation.
2. Shared database, schema per tenant
Each tenant gets its own schema with identical tables inside one database.
- Pros: Stronger logical separation, easier per-tenant backup and restore, and simpler data deletion.
- Cons: Migrations must run across every schema, the number of database objects grows with each tenant, and connection pooling and tooling become more complex.
3. Database per tenant
Each tenant has a dedicated database, sometimes on dedicated infrastructure.
- Pros: Strongest isolation, per-tenant performance tuning, data residency options, and a straightforward story for security reviews.
- Cons: Highest cost and operational overhead, migrations and monitoring across many databases, and harder cross-tenant reporting.
Comparison
| Shared schema | Schema per tenant | Database per tenant | |
|---|---|---|---|
| Isolation | Logical (policies) | Logical (schemas) | Physical |
| Cost per tenant | Lowest | Low to moderate | Highest |
| Migrations | One run | One per schema | One per database |
| Noisy-neighbor risk | Highest | Moderate | Lowest |
| Per-tenant restore | Hard | Moderate | Easy |
| Best for | Most B2B and B2C SaaS | Mid-size tenant counts with stronger separation needs | Enterprise, regulated, or data-residency customers |
The hybrid model
Many mature SaaS platforms combine models: most customers live in a shared database, while large or regulated customers get a dedicated database on a premium plan. To make this possible later, design from day one so that:
- Every tenant-owned table has a tenant identifier.
- All data access goes through one layer that knows the current tenant.
- Tenant routing, meaning which database a tenant lives in, is a lookup rather than hard-coded.
Making the shared model safe in PostgreSQL
If you choose a shared schema, defend against cross-tenant leaks at several layers:
- Row-level security policies that compare each row's
tenant_idto the current tenant set for the session or derived from the authenticated user. - Indexes that start with
tenant_idon large tables, so per-tenant queries stay fast. - Foreign keys that include
tenant_idwhere practical, so records cannot reference another tenant's data. - Automated tests that log in as one tenant and confirm they cannot read or change another tenant's records.
- Per-tenant rate limits and quotas to reduce noisy-neighbor problems.
Platforms such as Supabase build on PostgreSQL row-level security, which makes this pattern a natural fit.
Other tenancy decisions
- Identity: Can one user belong to several tenants? Most B2B products need this, so model memberships separately from users.
- Configuration: Store per-tenant settings, feature flags, and plan limits in their own tables.
- File storage: Prefix object storage paths with the tenant ID and apply the same access rules as the database.
- Background jobs: Pass the tenant ID explicitly to every job and log it for debugging.
- Data deletion: Plan how to export and fully delete a tenant's data when a customer leaves.
Where to start
Write down your likely customer mix for the next two years, including whether any will require dedicated infrastructure or data residency. If not, start shared, enforce isolation in the database, and keep the door open for dedicated tenants later. If you want help designing or reviewing your architecture, our custom SaaS backends team builds multi-tenant platforms on PostgreSQL, Supabase, and Node.js.