Skip to content
Engineering4 min read

Multi-tenant SaaS architecture: choosing an isolation model

Shared database, schema per tenant or database per tenant? How to choose a multi-tenancy model for your SaaS product, and the security and operational details that go with it.

Published
Isometric stacked layers split into separate compartments on a dark grid

Key takeaways

  • Multi-tenancy is a spectrum, from fully shared to fully isolated.
  • A shared database with a tenant ID suits most early-stage SaaS products.
  • Enforce tenant isolation in the database, not only in application code.
  • Design for moving large or regulated tenants to dedicated infrastructure later.

Most SaaS products serve many customers from one codebase. How you separate those customers' data and workloads is one of the earliest architectural decisions you make, and one of the hardest to change later.

This guide compares the common multi-tenancy models and the details that make each one safe to run. If you're still validating the idea, see how much it costs to build an MVP first.

The three main models

ModelHow it worksIsolationCost per tenantOperational effort
Shared database, shared schemaAll tenants in the same tables, separated by a tenant_idLogicalLowestLowest
Schema per tenantOne database, a separate schema for each tenantStrongerMediumMedium (migrations per schema)
Database per tenantEach tenant gets its own databaseStrongestHighestHighest

Some products go further and give large customers their own application stack. That's usually a premium tier rather than the default.

Shared database, shared schema

Every table that holds tenant data has a tenant_id. Every query filters by it.

Good for: early-stage products, many small tenants, fast iteration.

Risks: a single missing filter can leak data across tenants, and a heavy tenant can slow everyone down.

Enforce isolation in the database

Don't rely on developers remembering WHERE tenant_id = ?. In PostgreSQL, row-level security can enforce it:

sql
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;

CREATE POLICY tenant_isolation ON invoices
  USING (tenant_id = nullif(current_setting('app.tenant_id', true), '')::uuid);

The application sets app.tenant_id at the start of each request, and the database refuses to return other tenants' rows even if a query forgets the filter.

The nullif(..., '') matters. On a pooled connection that has had the setting before, PostgreSQL can return an empty string instead of NULL, and casting '' to uuid raises an error. With nullif, a request with no tenant set simply matches no rows. Wrap the expression in a small SQL function so every policy uses the same safe version.

Schema per tenant

Each tenant gets its own set of tables inside one database.

Good for: moderate numbers of tenants that need some customisation or easier per-tenant export and restore.

Watch out for: migrations must run across every schema, and connection pooling gets more complex as tenant numbers grow.

Database per tenant

Good for: enterprise or regulated customers who require separation, data residency in a specific region, or very different usage patterns.

Watch out for: provisioning, migrations, backups and monitoring multiply with every tenant. You need automation from day one.

A hybrid approach

Many products combine models:

  • Standard tiers on a shared database.
  • Enterprise customers on dedicated databases, sometimes in their preferred region.

Design a tenant directory that records where each tenant's data lives, so the application can route requests and you can move a tenant later.

Beyond the database

Identity and access

  • Resolve the tenant from the subdomain, custom domain or authenticated session, never from a value the client can edit freely.
  • Support roles within a tenant (owner, admin, member) and, for business customers, single sign-on.
  • Strengthen login with modern methods; see passkeys vs OTP.

Noisy neighbours

  • Rate-limit APIs per tenant.
  • Push heavy work into queues with per-tenant concurrency limits.
  • Monitor resource use per tenant so you can spot and move outliers.

Configuration and feature flags

Store per-tenant settings, plan limits and feature flags centrally. Avoid forking code for individual customers.

Data export and deletion

Customers will ask for their data and expect it deleted when they leave. Build export and tenant deletion early; privacy laws like India's DPDP Act make it an obligation, as covered in our DPDP checklist.

Observability

Tag logs, metrics and traces with the tenant ID. When a customer reports a problem, you should be able to see their requests in seconds.

Testing

Add automated tests that try to read and write across tenants and must fail. Treat any cross-tenant access as a critical bug.

Choosing a model

If you…Start with
Expect many small customers and need to move fastShared schema with row-level security
Need per-customer customisation and easy restoresSchema per tenant
Sell to enterprises with strict isolation or residency requirementsDatabase per tenant for those customers

Where to start

Add tenant_id and tenant-aware request handling from the first commit, enforce isolation in the database, and keep a tenant directory so you can move customers later.

Our custom software team designs and builds SaaS platforms, from first architecture decisions to production. Talk to us about your SaaS product.

Frequently asked questions

What is multi-tenant architecture?

It's a design where one running application serves many customers (tenants), with each tenant's data and configuration kept separate. It's how most SaaS products keep costs down and ship updates to everyone at once.

Which multi-tenancy model is best?

There's no single best model. A shared database with a tenant ID column is simplest and cheapest. Separate schemas or databases give stronger isolation and per-customer flexibility at higher operational cost. Many products mix models by customer tier.

How do you prevent one tenant seeing another tenant's data?

Scope every query by tenant, enforce it centrally rather than in each query, use database features such as PostgreSQL row-level security, and test for cross-tenant access in automated tests.

What is the noisy neighbour problem?

When one tenant's heavy usage slows the system down for everyone else. Rate limits, per-tenant quotas, background job queues and the option to move large tenants to dedicated resources address it.

Can we start single-tenant and switch later?

You can, but it's costly once you have many customers. Adding a tenant ID and tenant-aware design early is cheap and keeps your options open.

  • SaaS
  • Architecture
  • Databases
Portrait of Noeal Rajeev Thaleeparambil

Written by

Co-Founder & CTO

Excels in developing innovative hardware and software solutions. With expertise in IoT, embedded systems, and data analytics, committed to tackling real-world challenges through advanced technology.

Keep reading

Three isometric gauges of increasing height on a light grid
Engineering

Fixing Core Web Vitals on a Next.js site: LCP, INP and CLS

A practical guide to measuring and improving Largest Contentful Paint, Interaction to Next Paint and Cumulative Layout Shift on Next.js sites, with the fixes that make the biggest difference.

BreaktroughF1 Team · 4 min read

Newsletter

Get new articles in your inbox.

Practical notes on building software, hardware and products. No spam — unsubscribe anytime.