Software Engineering

Multi-Tenant SaaS Architecture: Choosing a Tenancy Model

Abstract illustration for the article Multi-Tenant SaaS Architecture: Choosing a Tenancy Model

A multi-tenant application serves many customers, called tenants, from one running system. How you separate their data and configuration is one of the most important early decisions in a SaaS product, because it is expensive to change later.

The three common models

ModelHow it worksStrengthsTrade-offs
Shared database, shared schemaAll tenants share tables, each row tagged with a tenant identifierLowest cost, simplest to operate at scaleIsolation depends on correct queries and access rules
Shared database, schema per tenantEach tenant has its own schema in one databaseStronger separation, easier per-tenant customizationMigrations run once per tenant; limits appear with many tenants
Database per tenantEach tenant has a dedicated databaseStrongest isolation, simple per-tenant backup and restoreHighest cost and operational effort

Choosing a model

  • Many small customers? Shared tables are usually the most economical.
  • A few large customers with strict isolation or regulatory needs? Consider separate schemas or databases.
  • Mixed customers? A hybrid is common: shared infrastructure by default, dedicated resources for tenants that need them.

Decisions that are hard to change later

  1. Tenant identity everywhere. Every request, job and log entry should carry the tenant. Retrofitting this is painful.
  2. Enforced isolation. Do not rely on developers remembering to filter by tenant. Enforce it centrally, and where the database supports it, at the database level as well.
  3. Configuration and entitlements. Plan for per-tenant settings, feature flags and plan limits early.
  4. Migrations. Decide how schema changes roll out across tenants, and how to stage them safely.
  5. Identity and roles. Separate a user's identity from their membership and role within each tenant.

Operating a multi-tenant system

  • Noisy neighbors. One tenant's heavy usage should not slow others. Use rate limits, queues and resource limits.
  • Observability by tenant. Be able to filter logs, metrics and errors for a single tenant.
  • Backup and restore. Know how you would restore one tenant without affecting the rest.
  • Data lifecycle. Design export and deletion of a tenant's data from the beginning.

Start simple, but keep the door open

Most products begin with shared tables and a tenant identifier. That is a sound choice as long as isolation is enforced centrally and the code does not assume there will never be a dedicated tenant. A little foresight here avoids a costly rebuild when your first large customer arrives.

Keep reading

More insights

Want to apply this to your business?

Talk to our engineers about your situation. We will give you honest advice.