Concepts

Multi-tenant architecture patterns for SaaS, compared

Every B2B product has to answer one question early: how are one customer’s data and workload kept apart from another’s? The answer sets your cost, your support burden and your security story for years.

7 min read · Last checked

In short

Key points

  • There is no single right pattern. Each trades isolation against cost and operating effort.
  • Shared tables with a tenant column are the cheapest to run and the easiest to get wrong. Enforce the filter in one place.
  • Per-customer databases give strong separation and make fleet operations harder as customer count grows.
  • Most products mix patterns, with a shared default and dedicated resources for customers who pay for them.

The range of choices

Microsoft’s architecture guidance frames multi-tenancy as a spectrum. At one end you share every resource among all tenants. At the other you deploy isolated resources for every tenant. Deploying separate resources for each customer can work for a few customers, but it typically lacks cost efficiency and makes resource management difficult. Most designs sit between the extremes, and each position trades scale, isolation, cost efficiency, performance, implementation complexity and manageability.

Pattern 1: shared tables with a tenant column

All customers share the same database and tables, and every row carries a tenant identifier. It is the cheapest to run and the simplest to deploy, because one schema migration covers everyone.

The risk is that isolation lives entirely in your code and queries. A single missing filter exposes another customer’s data. Reduce that risk by making the filter hard to forget: apply it through a data-access layer or a global query filter instead of in each query, add tests that create two tenants and prove one cannot read the other, and consider database row-level security, which PostgreSQL supports, as a second line of defence.

  • Strengths: lowest cost, simple migrations, easy cross-customer reporting for your own team.
  • Weaknesses: one bug can leak data, one heavy customer can slow everyone (the noisy neighbour problem), and per-customer backup or restore is awkward.

Pattern 2: a schema for each customer

Customers share a database server but each has its own schema. Separation is stronger than a column, because a query has to name the schema. Per-customer export and restore get simpler.

The cost appears at scale. Every schema change must be applied to every schema, and large numbers of schemas strain tooling and connection handling.

Pattern 3: a database for each customer

Each customer has its own database. Isolation, backup, restore and data location are the easiest to explain to a security reviewer, and a noisy customer cannot overload another’s database.

You pay for it in infrastructure and in operations: more connections to manage, migrations that must be orchestrated across the fleet, and reporting that has to gather data from many places. Microsoft’s guidance notes that this approach works well with a few tenants and gets harder to manage as the number grows.

Pattern 4: deployment stamps

The Deployment Stamps pattern deploys a complete, dedicated set of infrastructure for one tenant or for a group of tenants. A single-tenant stamp gives the highest isolation and avoids the noisy neighbour problem, and lets you meet a customer’s regional or availability needs. The main drawback is the infrastructure cost, which your pricing has to offset. A stamp can also serve several tenants, which brings the sharing and the cost savings back.

How to choose

  • Start with the strongest isolation your customers’ contracts require, not the strongest you can imagine.
  • If your customers are many and small, a shared design with strict enforcement and tests usually wins on cost.
  • If your customers are few and large, or regulated, dedicated databases or stamps are easier to justify, and your price should carry the cost.
  • Keep the door open. If every data access goes through one tenant-aware layer, you can move a large customer to dedicated resources later without rewriting the app.

What the platform handles for you

Whichever pattern you pick for your product data, the accounts layer is the same for every app. With TenancyEngine, each customer is a tenant with its own members, roles and plan, your sign-in tells your app which tenant a person is working in, and the runtime context returns the features and limits for that tenant. Your own database stays yours: the platform does not hold your product data, and you decide how it is separated.

Honest limits

What to know before you rely on this

  • TenancyEngine manages customers, members, roles, plans and usage. It does not provide or manage the database that holds your own product data.

Questions people ask

Is a tenant column secure enough?

It can be, if the filter is applied in one enforced place and covered by tests that prove one tenant cannot read another. It is the pattern where a single mistake does the most damage, so treat enforcement as a feature.

What is the noisy neighbour problem?

It is when one customer’s heavy use slows down others who share the same resources. Dedicated resources avoid it. Shared designs manage it with limits and monitoring.

Can I change patterns later?

Yes, if all data access goes through a tenant-aware layer. Moving a customer is then a data migration and a configuration change, not a rewrite.

Sources

Keep reading

Try it on the free plan

One app and five customers, no credit card required.

Request access More guides