Skip to content

Multi-Tenant SaaS Architecture: Models, Tradeoffs and a Laravel Example

Multi-tenancy means many customers share one application with their data kept apart. Compare the three common data models and choose by isolation needs, not fashion.

Multi-tenant SaaS architecture means one running application serves many customers, called tenants, while keeping each tenant's data separate. The main design choice is where tenant data lives: in shared tables, in a separate schema per tenant, or in a separate database per tenant. Each option trades isolation against cost and operational effort.

For most early products, shared tables with a tenant identifier on every row is the simplest start. The sections below explain when that stops being enough.

Tenant, user and account are different things

Be precise from the beginning:

  • A tenant is the customer organisation that owns data. It might be a company, a clinic or a team.
  • A user is a person. One user can belong to several tenants.
  • An account is often used loosely for either, which causes confusion in the data model.

If you model "user owns data" instead of "tenant owns data", adding teams later becomes a painful migration. Store ownership on the tenant and link users to tenants through a membership record with a role.

The three data models

1. Shared database, shared tables

Every tenant-owned table has a tenant_id column. All tenants use the same tables.

Strengths: the simplest to build and operate, a single migration applies to everyone, and cross-tenant reporting for your own team is easy.

Weaknesses: isolation depends entirely on your code adding the tenant filter every time. One missed filter can expose another tenant's data. Heavy tenants can slow others down, and per-tenant restore from a backup is difficult.

2. Shared database, schema per tenant

Each tenant gets its own schema inside one database engine. Support for schemas depends on the database; PostgreSQL has them as a first-class feature, while MySQL treats schema and database as the same thing.

Strengths: stronger separation than a column filter, and the tenant filter is no longer needed in every query.

Weaknesses: migrations must run once per tenant, and large numbers of schemas add operational overhead.

3. Database per tenant

Each tenant has its own database, and the application connects to the right one for each request.

Strengths: the strongest isolation, simple per-tenant backup and restore, and the option to move a large tenant to its own server.

Weaknesses: the most operational work. Migrations run for every database, connection management is harder, and reporting across tenants needs extra tooling.

Comparing them against what you need

Instead of picking a favourite, score your product on these questions:

  • Will customers ask for contractual or technical data separation?
  • Will tenant sizes vary widely?
  • Do you need per-tenant restore or export?
  • How many tenants do you expect to run, and how small is your operations team?
  • Do you need to look across all tenants for analytics?

If separation and per-tenant restore matter a lot, lean towards separate databases. If you expect many small tenants and a small team, lean towards shared tables. Schema per tenant sits in between and is tied to your database engine.

Decision rule for an MVP

  1. Start with shared tables and a tenant_id on every tenant-owned table.
  2. Make tenant scoping automatic in one place, not in each query.
  3. Add tests that try to read tenant B's data while authenticated as tenant A.
  4. Keep the tenant resolution (subdomain, path or login) behind one service, so the storage model can change later.
  5. Move to separate databases only when a real requirement appears.

Compliance requirements are a legitimate reason to choose stronger isolation, but a data model alone does not make a product compliant. Check the actual obligations with a qualified adviser.

A Laravel example: automatic tenant scoping

Laravel supports global scopes on Eloquent models. You can use one to add the tenant filter to every query, and a model event to set the tenant on create.

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class TenantScope implements Scope
{
    public function apply(Builder $builder, Model $model): void
    {
        $tenantId = app(CurrentTenant::class)->id();

        if ($tenantId !== null) {
            $builder->where($model->getTable() . '.tenant_id', $tenantId);
        }
    }
}
trait BelongsToTenant
{
    protected static function bootBelongsToTenant(): void
    {
        static::addGlobalScope(new TenantScope());

        static::creating(function (Model $model) {
            $model->tenant_id ??= app(CurrentTenant::class)->id();
        });
    }
}

Here CurrentTenant is your own class, resolved from the request. Note the weak point: when no tenant is resolved, this scope applies no filter. Queue jobs, console commands and raw queries run outside a request, so decide explicitly how they get their tenant, and fail loudly if none is set rather than falling back to "all rows". Global scopes also do not apply to query-builder calls that bypass Eloquent, and model events such as creating do not fire for bulk inserts, so the tenant must be set explicitly there.

Failure modes to design against

Missing filter in raw queries. Reports and exports are often written with raw SQL. Review them with the same care as controllers.

Cached data without a tenant key. If a cache key does not include the tenant, one tenant can read another's cached result.

File storage. Uploaded files need tenant-scoped paths and access checks, not only a database filter.

Background jobs. A job must carry the tenant identifier and restore the context when it runs.

Unique constraints. An email unique across the whole table may need to be unique per tenant instead.

Noisy tenants. One tenant running a large import should not slow everyone else. Plan queues and limits.

Questions to settle before you build

  • How does a request identify its tenant: subdomain, path or session?
  • Can a user belong to several tenants, and how do they switch?
  • What happens to a tenant's data when they cancel?
  • Who can see data across tenants inside your own team, and is it logged?

How we work with this at LaunchSprintAI

For SaaS builds we settle the tenant model in the brief, before any screen is designed, and write the isolation tests early. AI tools help engineers with boilerplate and review, and engineers decide and check the architecture. Scope and requirements, not a template, shape the result. For where this fits in a first release, see From Idea to MVP Brief: Our Structured Approach.

If you are planning a multi-tenant product, see our MVP development page or start a project brief.

Frequently asked questions

Is shared-table multi-tenancy safe? It can be, if scoping is enforced centrally and tested. Its risk is that a single mistake exposes data, which is why tests matter.

Can I change the model later? Yes, but it is real migration work. Keep tenant resolution and data access behind clear boundaries to lower the cost.

Do I need multi-tenancy for an MVP? If customers are organisations with several users each, yes in some form. A single-user product may not need it yet.

Related reading

Related services

Also on LaunchSprintAI

Our hosting

Built your app with AI? Get it online.

MoodLensAI runs apps made with Claude Code, Codex or Cursor, plus n8n, WordPress and Laravel, on a managed server with HTTPS, backups and monitoring. Fixed monthly plans, no server administration.