All posts
Architecture

Designing Multi-Tenant SaaS the Right Way

11 min read

Tenancy is the decision you make once and live with for years. Pick the wrong isolation model and you either fight noisy neighbours forever or drown in operational overhead. Here is how to reason about it.

The Three Models

Every multi-tenant system lands on one of three isolation strategies. The trade-off is always the same: isolation versus cost.

Single Database, Shared Schema

All tenants share tables, separated by a `tenant_id` column. It is the cheapest to run and the easiest to query across tenants, but a single missing scope leaks data between customers. Enforce the boundary with a global Eloquent scope so no query can forget it.

Schema Per Tenant

Each tenant gets its own schema inside one database. You get cleaner isolation and per-tenant migrations, at the cost of connection juggling and slower cross-tenant reporting.

Database Per Tenant

Maximum isolation: each tenant is a separate database. Ideal for enterprise contracts with strict data residency needs, but the operational surface grows linearly with your customer count.

Choosing a Model

Start with the shared schema unless a customer contract forces otherwise. It is by far the simplest to operate, and you can migrate the largest tenants to dedicated databases later.

When to Split

Split a tenant out when it becomes a noisy neighbour, when compliance demands physical separation, or when a single customer outgrows the shared cluster.

Operational Reality

Whatever model you pick, automate tenant provisioning end to end. Manual onboarding is fine for ten tenants and a disaster at a thousand.

Migrations at Scale

With per-tenant databases, migrations must run across every tenant reliably and resumably. Build a command that iterates tenants, records progress, and can restart from where it failed.

Closing Thoughts

Tenancy is not a framework feature you bolt on; it is an architectural spine. Decide deliberately, enforce the boundary in code, and automate everything around provisioning.