Software Engineering · Practical Architecture Guide

Multi-Tenant SaaS Architecture: Tenancy Models, Isolation and How to Choose

Multi-tenant SaaS serves many customers from one application while keeping each customer's data separate. The main choice is how to separate data: a shared database with a tenant ID, a schema per tenant or a database per tenant. Most products start shared with strong isolation in code and the database, then move large or regulated tenants to their own resources.

Lexvaxa diagram of the three multi-tenant data models: shared database with tenant ID, schema per tenant and database per tenant.

Who this guide is for

  • SaaS founders and product leads planning a product that will serve many business customers.
  • CTOs and senior engineers choosing a tenancy model or fixing one that no longer scales.
  • Agencies turning a client tool into a product that other companies will sign up for.

Key topicsmulti-tenant SaaS architecturemulti-tenant SaaSmulti-tenant database designtenant isolationmulti-tenant SaaS development

What is multi-tenant SaaS architecture?

In a multi-tenant SaaS product, one running application serves many customer organisations, called tenants. Each tenant sees only its own users, data and settings, but they share the same code, infrastructure and release cycle. Single-tenant means each customer gets a separate copy of the application and its infrastructure.

Multi-tenancy lowers the cost of serving each customer and lets you ship one update to everyone. The price is design discipline: every query, file, cache key, background job and log line must know which tenant it belongs to, because one missed filter can show one customer another customer's data.

  • Tenant: a customer organisation with its own users, data and settings.
  • Isolation: the guarantees that stop tenants seeing or affecting each other.
  • Noisy neighbour: one tenant's heavy use slowing everyone else down.
  • Control plane: the shared services for sign-up, billing, tenant settings and operations.

The three data models

Microsoft's Azure Architecture Center and the AWS whitepaper on SaaS tenant isolation describe the same spectrum: the more you share, the cheaper and simpler operations become, and the more you rely on your own code for isolation.

  • Shared database, shared schema: every table has a tenant ID column. Cheapest and simplest to run, easiest to report across tenants; isolation depends on every query filtering by tenant.
  • Schema per tenant: one database, a separate schema for each tenant. Stronger separation and easier per-tenant backup; migrations must run across many schemas, which gets slow past a few hundred tenants.
  • Database per tenant: each tenant has its own database. Strongest isolation, per-tenant restore and data location; highest cost and the most operational work for migrations, monitoring and connections.
  • Hybrid: shared for most tenants, dedicated databases for large, regulated or premium tenants. Common in mature products.

How to enforce tenant isolation

Isolation should not depend on developers remembering a WHERE clause. Resolve the tenant once per request from the authenticated user or the subdomain, put it in the request context, and make the data layer apply it automatically. In PostgreSQL, row-level security policies can enforce the tenant filter inside the database itself, so a query that forgets the filter returns nothing instead of another tenant's rows.

Apply the same rule everywhere data lives: file storage paths and buckets, cache keys, search indexes, message queues, analytics events and logs. Background jobs need the tenant passed explicitly, since there is no web request to read it from. Then test it: automated tests that sign in as one tenant and try to read another tenant's records should fail on every endpoint.

  • Resolve the tenant once, from the token or subdomain, never from a value the client can change freely.
  • Enforce the filter in the data layer and, where possible, with database row-level security.
  • Prefix storage paths, cache keys and search indexes with the tenant ID.
  • Write cross-tenant access tests and run them on every release.

Noisy neighbours, scaling and performance

In a shared system one tenant running a huge import or report can slow everyone else. Protect against it with per-tenant rate limits and quotas, queues for heavy work, and timeouts on expensive queries. Index tables with the tenant ID first so each tenant's queries stay fast as the total data grows.

Measure per tenant, not only overall. Dashboards that show requests, errors, latency and storage per tenant let you spot the customer who needs a higher plan, a dedicated database or a conversation about usage before others notice.

Identity, roles and tenant settings

Users belong to a tenant, and often to several: a consultant may work for three client accounts. Model memberships explicitly, with roles per tenant, and let users switch tenants without signing in again. Larger customers will ask for single sign-on through SAML or OpenID Connect, SCIM user provisioning and audit logs, so leave room for them in the design.

Keep per-tenant configuration, such as plan limits, enabled features, branding and data region, in one tenant settings service rather than scattered across the code. Feature flags per tenant make it possible to trial new features with a few customers before everyone.

Billing, onboarding and operations

A SaaS product needs a control plane alongside the application: sign-up and tenant creation, plan and usage tracking, billing through a provider such as Stripe, suspension and deletion, and support tools that let staff see a tenant's state safely. Automate tenant creation fully, including any schema or database it needs, so onboarding takes seconds, not a support ticket.

Plan for the end of a customer relationship too: data export, deletion within an agreed period and evidence that it happened. These are often contract and privacy requirements, especially in Europe under the GDPR.

How to choose a tenancy model

For most new B2B products, start with a shared database and shared schema, with the tenant ID enforced in the data layer and by row-level security. It is the cheapest to run and the fastest to build, and it can grow a long way. Design the code so a tenant's data could later move to its own database without a rewrite.

Choose schema or database per tenant from the start when customers require it: regulated data, contractual data residency, per-customer encryption keys or very large tenants with different performance needs. If you are unsure, write down your three largest expected customers' requirements; they usually decide it.

  • Many small and mid-size tenants: shared database, shared schema.
  • Dozens of tenants with strict separation needs: schema or database per tenant.
  • Mixed customer base: shared by default, dedicated for enterprise plans.

Frequently asked questions

What is the difference between single-tenant and multi-tenant SaaS?

Single-tenant SaaS runs a separate copy of the application and infrastructure for each customer. Multi-tenant SaaS serves all customers from one application, with each customer's data kept separate by design. Multi-tenant is cheaper to run and update; single-tenant gives the strongest separation.

Which multi-tenant database model is best?

For most new B2B products, a shared database with a tenant ID on every table, enforced in the data layer and with row-level security. Schema or database per tenant suits regulated data, data residency requirements or very large customers.

How do you prevent data leaks between tenants?

Resolve the tenant from the authenticated session, apply the tenant filter automatically in the data layer, use database row-level security where available, prefix storage and cache keys with the tenant ID, and run automated cross-tenant access tests on every release.

Can I move from shared to database per tenant later?

Yes, if the code always scopes data by tenant and does not rely on joins across tenants. Then a tenant's rows can be copied to a dedicated database and the tenant routed there. Planning for this early avoids a rewrite.

How long does it take to build a multi-tenant SaaS MVP?

A focused MVP with tenant sign-up, roles, the core feature, billing and an admin view often takes two to four months. Single sign-on, audit logs, data residency and complex billing add time.

PRACTICAL NEXT STEP

Design your SaaS architecture before you build

We review your customers, data and compliance needs, choose the tenancy model with you and build a multi-tenant product that can grow without a rewrite.

Sources and further reading

Official documentation and original research supporting this guide. Product behavior and guidance can change; check the linked source for current details.

Keep exploring

Related guides, projects and industries.

Let’s build it together

Make the next technical decision with clarity.

Tell us what you want to build or fix. Within one business day an engineer replies with a clear first step: scope, timeline and a realistic budget range. No obligation.

Start your free plan
  • Reply in under 1 day
  • Free 30-minute call
  • Your idea stays confidential
Book a free call

30-minute discovery call

Book a free call with Lexvaxa

Calendar not loading? Open the booking page