Skip to content

Multi-Tenant SaaS Architecture: Data Isolation Patterns Compared

Engineering7 min readBy the Nexzem team

Shared tables with tenant IDs, schema per tenant or database per tenant: how each isolation pattern works, what it costs and how to enforce it safely.

In this article
  1. 01What multi-tenancy means
  2. 02Pattern 1: Shared database, shared schema
  3. 03Enforcing isolation in a shared schema
  4. 04Pattern 2: Shared database, schema per tenant
  5. 05Pattern 3: Database per tenant
  6. 06Pattern 4: Hybrid and tiered models
  7. 07Side-by-side comparison
  8. 08Beyond the database
  9. 09Tenant lifecycle: onboarding, export and deletion
  10. 10Migrations and releases across tenants
  11. 11Noisy neighbors and fair use
  12. 12How to choose

What multi-tenancy means

A multi-tenant SaaS application serves many customer organizations, called tenants, from one product. Each tenant must see only its own data, while you run one codebase and, ideally, one deployment process. The central design decision is how strongly tenants' data is separated: logically in the same tables, in separate schemas, in separate databases or a mix of these.

There is no single right answer. Stronger isolation costs more to run; weaker isolation costs more care in code. The right pattern depends on how many tenants you expect, how large they are, what your customers' security reviews demand and how much operational work your team can absorb.

Pattern 1: Shared database, shared schema

All tenants share the same tables, and every tenant-owned row carries a tenant_id column. This is the most common starting point, often called the pool model. It is the cheapest to run, schema migrations happen once, cross-tenant analytics are easy and onboarding a tenant is just inserting a row.

The risk is a missing tenant filter. One query without WHERE tenant_id = ... exposes another customer's data. The pattern is safe only when isolation is enforced centrally rather than remembered in every query, which the next section covers.

Enforcing isolation in a shared schema

Do not rely on developers adding a filter by hand. Use layers of defense:

  • Resolve the tenant once per request, from the subdomain, a header or a token claim, and store it in request context
  • Scope all data access through a repository or ORM layer that adds the tenant filter automatically
  • Enable PostgreSQL Row-Level Security policies that compare tenant_id with a session setting, so even a forgotten filter returns nothing
  • With connection pooling, set the tenant setting with SET LOCAL inside each transaction so it cannot leak to the next request on the same connection
  • Include tenant_id in unique constraints and as the leading column of most indexes
  • Add automated tests that try to read and write across tenants and must fail

Pattern 2: Shared database, schema per tenant

Each tenant gets its own schema with identical tables inside one database. Queries run against the tenant's schema, selected through the search path or qualified names. Isolation is stronger, since a query cannot accidentally reach another tenant's tables, and per-tenant backup, restore or export is simpler.

The costs show up with scale. Every migration must run across every schema and can partially fail. Thousands of schemas strain database catalogs, tooling and connection handling. This pattern suits products with tens to a few hundred tenants, not tens of thousands of small ones.

Pattern 3: Database per tenant

Each tenant gets its own database, sometimes its own server or cloud account. This is the silo model. Isolation is strongest, noisy neighbors disappear, tenants can be placed in specific regions for data residency, restored independently and even given their own encryption keys. Enterprise and regulated customers often ask for it.

It is also the most expensive and operationally heavy: provisioning automation, migrations across many databases, monitoring per database and higher baseline cost per tenant. Without strong automation, it does not scale beyond a modest number of tenants.

Pattern 4: Hybrid and tiered models

Many mature SaaS products combine patterns: small tenants share a pooled database, while large or regulated tenants get dedicated databases, sold as a premium tier. Some go further with a cell-based design, where groups of tenants run on independent copies of the whole stack, limiting the blast radius of failures.

To keep this possible later, put a routing layer in place early: a tenant directory that maps each tenant to its database or cell. Code asks the directory where a tenant lives rather than assuming one database.

Side-by-side comparison

The patterns trade isolation against cost and effort:

  • Shared schema: lowest cost, simplest operations, isolation enforced in code and policies, noisy neighbor risk
  • Schema per tenant: stronger logical isolation, easier per-tenant restore, migrations and catalog size become painful at scale
  • Database per tenant: strongest isolation, residency and per-tenant keys, highest cost and automation needs
  • Hybrid: matches isolation to customer tier, needs a tenant routing layer from early on

Beyond the database

Tenant isolation is not only a database concern. Every shared component needs a tenant boundary:

  • Caches: include the tenant ID in every cache key
  • Object storage: use per-tenant prefixes or buckets and check access on every download
  • Background jobs and queues: carry the tenant ID in every message and restore context in the worker
  • Search indexes and vector stores: filter or partition by tenant
  • Logs and metrics: tag with tenant ID for support and per-tenant usage tracking

Tenant lifecycle: onboarding, export and deletion

Design for the whole tenant lifecycle, not just day-to-day use. Onboarding should be automated, including creating schemas or databases if you use them, seeding defaults and registering the tenant in the directory. Enterprise customers will ask for a full data export, and privacy laws and contracts require deleting a tenant's data when they leave, including copies in caches, search indexes, object storage, analytics tools and, eventually, backups. Each is easy to plan early and painful to retrofit.

Keep a record of where each tenant's data lives. That inventory is also what security questionnaires and data protection reviews ask for.

Migrations and releases across tenants

With a shared schema, a migration runs once. With schema or database per tenant, it runs many times, so treat it as a fleet operation: run it tenant by tenant with progress tracking, make it safe to retry, and let the application work with both old and new schema while the rollout completes. Roll out to internal and low-risk tenants first. The expand and contract approach to schema changes matters even more here, because tenants may sit on different schema versions for hours.

Noisy neighbors and fair use

In pooled models, one tenant's heavy import or report can slow everyone else. Apply rate limiting and quotas per tenant, run heavy jobs through queues with per-tenant concurrency limits and watch per-tenant resource usage. When one tenant consistently dominates, that is a signal to move them to dedicated resources, which the hybrid model makes possible.

At large scale, the shared database itself can be split by tenant across several nodes, a form of database sharding. Because nearly every query includes the tenant ID, it is a natural shard key.

How to choose

For most new B2B SaaS products, start with a shared schema, enforce isolation with a scoped data layer plus row-level security, and add a tenant directory so dedicated databases can be introduced for enterprise customers later. Choose schema or database per tenant from the start only if your early customers require it or you expect a small number of large tenants. Nexzem's SaaS development work starts with exactly this decision.

Planning something similar?

Get a straight answer on scope, cost and timeline.

Talk to the team

Tell us what you're building.

A solutions consultant replies within one business day with next steps, a rough estimate and a suggested team.