Skip to main content
← All insights

By

CTO @ Beautron.AI · AI Product Engineer

3 min read

Architecture / SaaS / Multi-tenancy / Azure

Choosing a tenancy model for multi-tenant SaaS

Shared schema, schema per tenant or database per tenant? The right answer depends on isolation requirements, tenant count and how you'll run migrations, not on fashion. Here's how I decide.

On Aspective Pro, a B2B networking platform, every organization gets its own isolated database, with separate admin and tenant modules on top. That was the right call there, but it isn't always. The tenancy model is one of the few early decisions that is genuinely expensive to change later, so it deserves a deliberate choice.

The three common models

Shared schemaSchema per tenantDatabase per tenant
IsolationLogical (a TenantId column)NamespacePhysical
Cost per tenantLowestLowHighest
Noisy neighborsMost exposedExposedLeast exposed
MigrationsOne runOne run per schemaOne run per database
Per-tenant restore or exportHardMediumEasy
Tenant count it suitsThousands to millionsHundredsTens to low thousands

Questions I ask first

1. What does a data leak between tenants cost? If tenants are businesses with contracts, compliance requirements or sensitive data such as CVs, a missing WHERE TenantId = @id is a serious incident. Physical isolation turns that class of bug into "can't happen".

2. How many tenants, and how big? A consumer app with a million tiny accounts can't afford a database each. A B2B platform with a few hundred organizations usually can, especially with pooled Azure SQL options.

3. Do tenants need to be treated differently? Per-tenant backups, data residency, "export everything we own" or "delete us completely" requests are trivial with a database per tenant and painful with a shared schema.

4. Who runs migrations, and how? This is the question teams forget. With a thousand databases, a schema change becomes a rollout, not a deployment.

Making database-per-tenant work

If you go physical, invest early in three things:

  • A tenant catalog. One small control database maps each tenant to its connection details, status and schema version. Every request resolves the tenant (from the subdomain, token claims or a header) and looks up its database through the catalog, with caching.
  • Migrations as a fleet operation. Run them per tenant with a job that records each tenant's version, can be retried, and tolerates some tenants being ahead of others. The application must handle both schema versions during the rollout.
  • Pooled compute. Elastic pools let many small tenant databases share capacity, so you don't pay for each one's peak.

Making a shared schema safe

If you go shared, don't rely on developers remembering a filter:

  • Enforce tenancy at the data layer: global query filters in Entity Framework, or row-level security in the database itself.
  • Make the tenant part of every key and index you query by.
  • Test for leaks explicitly: an automated test that runs as tenant A and asserts it can never read tenant B's rows.

The hybrid most platforms grow into

Many mature SaaS products end up hybrid: small tenants share a pooled database, and large or regulated tenants get their own. If you design tenant resolution through a catalog from day one, moving a tenant from "shared" to "dedicated" becomes an operational task instead of a rewrite.

Takeaways

  • Decide based on isolation needs, tenant count and migration strategy.
  • Database per tenant buys strong isolation and easy per-tenant operations, at the price of fleet-style migrations.
  • Shared schema is cheapest but needs enforced filters and leak tests.
  • A tenant catalog keeps your options open for a hybrid model later.

Working on something similar? Let's talk — or ask ARA, the assistant in the corner, about this article.

More insights