SaaS 9 min read

Multi-Tenant SaaS Architecture: What to Consider

For most growing platforms, multi-tenant SaaS architecture should start with a shared Postgres schema, tenant_id on every row, and row-level security as a backstop. Add per-tenant limits for noisy neighbors, and move only the tenants that need it to a dedicated schema or database.

Multi-tenant SaaS architecture isolation models diagram

Key takeaways

  • There are 3 common isolation models: shared schema with a tenant_id column, schema per tenant, and database per tenant.
  • Shared schema plus Postgres row-level security is the right default for most B2B SaaS. Move individual tenants to stronger isolation when a contract or workload demands it.
  • Row-level security stops data leaks, not noisy neighbors. You still need per-tenant rate limits, query timeouts, and fair job queues.
  • Table owners and roles with BYPASSRLS skip row-level security, so the app must connect as a separate, restricted role.
  • Plan migrations, per-tenant config, and usage metering in the first build. All 3 get harder with every tenant you add.

What is multi-tenant SaaS architecture?

Multi-tenant SaaS architecture means one running application serves many customer organizations (tenants), with each tenant’s data and configuration kept separate. The hard part isn’t serving many customers. It’s guaranteeing that tenant A never sees, slows down, or breaks tenant B.

Almost every B2B product ends up multi-tenant, whether or not anyone said the word in planning. The decisions that matter are where the isolation boundary sits (row, schema, or database), how it’s enforced, and what you do when one tenant’s workload starts hurting the others. Those decisions are cheap in the first migration and expensive after the hundredth customer, which is why they belong in scoping. Our guide to scoping a SaaS MVP lists multi-tenancy as one of the main things that moves a build’s size, and this post is the technical side of that line. For the other early decisions that are expensive to undo, see the SaaS architecture mistakes we see most.

Which tenant isolation model should you choose?

Start with a shared schema and a tenant_id on every tenant-owned row, enforced by Postgres row-level security. It’s the cheapest to run and the easiest to migrate, and you can still give one large or regulated tenant its own database later.

CriteriaShared schema (tenant_id)Schema per tenantDatabase per tenant
Isolation strengthLogical, enforced by app and RLSNamespace per tenant, same serverStrongest: separate database or instance
Infra cost per tenantLowestLow to moderateHighest
MigrationsRun onceLoop over every schemaLoop over every database
Noisy neighbor riskHighestHigh (shared server resources)Lowest
Cross-tenant reportingSimple queriesUnion across schemasNeeds a separate warehouse
Per-tenant backup and restoreHard (filtered export)Moderate (dump one schema)Easy
Scales to many tenantsYesStrains catalog and tooling in the thousandsOperationally heavy past dozens
Best forMost B2B SaaS, self-serve plansMid-size tenant counts with custom fields per tenantEnterprise or regulated tenants with contractual isolation

In practice, most mature platforms end up hybrid. The long tail of tenants lives in the shared pool, and a handful of large or regulated accounts get a dedicated database. If you’re selling into banks or other regulated buyers (the market for the KYC compliance platform we built), expect security questionnaires to ask how isolation works, and make sure the answer is something you can show, not just describe.

To keep that hybrid option open, route every request through a tenant resolver that returns a connection, not just an ID. On day one it always returns the shared pool. Later it can return a dedicated database for specific tenants without touching application code.

How do you enforce tenant isolation in a shared database?

Enforce it in two layers: scope every query by tenant_id in the application, and back that up with row-level security in Postgres so a forgotten WHERE clause returns nothing instead of another customer’s data.

Scope everything by tenant_id

Every tenant-owned table gets a non-null tenant_id, and it leads your composite indexes, for example (tenant_id, created_at). Unique constraints should include it too, so two tenants can each have an invoice numbered 1001. In the application, resolve the tenant once per request (from the subdomain, a JWT claim, or the session) and pass it through a repository or ORM scope that applies it automatically. Hand-written filters in every query are how leaks happen.

Add Postgres row-level security as the safety net

Once RLS is enabled on a table, rows are only visible when a policy allows them, and if no policy applies, the default is deny. A typical tenant policy reads the current tenant from a session setting:

ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
ALTER TABLE projects FORCE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON projects
  USING (tenant_id = current_setting('app.tenant_id', true)::uuid);

Set the value inside each transaction, not per connection, so a pooled connection can’t carry one tenant’s context into another tenant’s request. Since SET LOCAL won’t take a bind parameter, use set_config with its local flag:

BEGIN;
SELECT set_config('app.tenant_id', $1, true);
-- tenant-scoped queries here
COMMIT;

Passing true as the second argument to current_setting makes a missing setting return null, so a request that never set a tenant matches no rows. That’s failing closed, which is what you want.

Three details from the PostgreSQL row security documentation catch teams out. Table owners normally bypass RLS, which is why the example uses FORCE ROW LEVEL SECURITY. Superusers and roles with the BYPASSRLS attribute always bypass it, so the application should connect as a dedicated role that has neither. And unique, primary key, and foreign key checks always bypass RLS, so be careful about letting tenants probe for values they shouldn’t know exist, such as a globally unique email or slug.

Designing a multi-tenant platform?

Free 30-minute call to pressure-test your isolation model. No pitch, no pressure.

Book a free call

How do you stop noisy neighbors in a multi-tenant system?

Put limits on what any single tenant can consume, and measure usage per tenant so you can see the problem before customers report it. Row-level security does nothing here: it controls which rows a query sees, not how much CPU, I/O, or lock time it takes.

The usual defenses:

  • Per-tenant rate limits at the API gateway or middleware, keyed on tenant rather than IP.
  • Statement timeouts on the application role, so one runaway report can’t hold locks for minutes.
  • Fair job queues. A tenant importing 200,000 rows shouldn’t push everyone else’s emails to the back of a single queue. Partition queues or cap concurrency per tenant.
  • Read replicas for heavy reporting and exports, so analytics traffic stays off the primary.
  • Tenant tags in logs and metrics. If you can’t break down latency and query time by tenant, you’ll be guessing who the noisy neighbor is.

When a tenant consistently needs more than its share, that’s the moment to use the resolver and give it a dedicated database. It’s also a good sales conversation, because isolation and dedicated capacity are easy to price as a higher tier.

How do you handle per-tenant config, migrations, and billing?

Treat all three as platform features with their own data model, not as one-off code paths. Each one gets harder with every tenant you add, so the patterns need to exist before tenant number fifty.

Per-tenant configuration

Store plan limits, feature flags, branding, and integration credentials in tenant-scoped tables, and encrypt secrets at rest. Resist “if tenant == ‘acme'” branches in code. Every special case should be a setting that any tenant could, in principle, have turned on. Custom fields are the classic trap: a JSONB column with a per-tenant field definition table usually beats adding real columns for one customer. Per-tenant branding matters most in client portals, where each customer expects to see their own name on the screen.

Migrations

In a shared schema, a migration runs once, but it runs against every tenant’s rows at the same time, so it has to be safe on a busy, large table. Use expand-and-contract changes (add the new column, backfill in batches, switch reads, drop the old column later) instead of rewriting a table in one locking statement. With schema-per-tenant or database-per-tenant models, you also need tooling that runs migrations across every target, records which ones succeeded, and can resume after a partial failure. That tooling is the hidden cost of the stronger isolation models.

Billing and metering

Billing attaches to the tenant, not the user. Model the tenant’s plan, seats, and usage in your own database, and let a processor like Stripe own invoices and payment state, synced through webhooks. If you price on usage, record metered events per tenant as they happen rather than reconstructing them from logs at the end of the month. That’s why billing belongs in discovery for any custom SaaS development project: the pricing model shapes the account model underneath it.

The bottom line on multi-tenant SaaS architecture

If you’re working out how to build a multi-tenant SaaS application, the sensible default for a growing platform is a shared Postgres schema with tenant_id on every row, application-level scoping, and row-level security as the backstop, plus a tenant resolver so you can move specific tenants to their own database later. Add per-tenant limits and metrics before you need them, and design config, migrations, and billing around the tenant from the first build.

If you’re planning a platform or reworking one that’s outgrowing its first design, take a look at our approach to SaaS development, or book a free call and bring your schema.

Common questions

What is multi-tenant SaaS architecture?

Multi-tenant SaaS architecture is a design where one running application and its infrastructure serve many customer organizations, called tenants, while keeping each tenant’s data and settings separate. Isolation can sit at the row level with a tenant ID, in a schema per tenant, or in a separate database per tenant.

What is a main advantage of multi-tenant SaaS architecture?

The main advantage is efficiency: every customer runs on the same codebase and shared infrastructure, so hosting costs per customer stay low and one deployment updates everyone at once. Fixes, features, and migrations ship once instead of once per customer, which lets a small team support a large number of tenants.

Is SaaS multi-tenant?

Most SaaS products are multi-tenant, because serving every customer from one application is cheaper to run and easier to update. It isn’t required, though. Some vendors offer single-tenant deployments for enterprise or regulated buyers, and many mature platforms run a hybrid, with most customers shared and a few on dedicated databases.

When should a SaaS use a database per tenant?

When a specific tenant needs it: a contract that requires physical data isolation, a data residency rule, or a workload heavy enough to hurt everyone else. For the rest of your customers, a shared schema is cheaper and simpler. Many platforms run both, with a resolver choosing the database per tenant.

Have something to build? Let's talk.

Free 30-minute call with no pitch and no pressure. We'll talk honestly about what you need and whether we're the right fit.

Book a free call

Our Work

All Work

Riesgo Pro

SaaS / Apps

A KYC compliance platform for financial institutions. It covers watchlist screening, real-time risk scoring and remote client onboarding.

View more

Realtor Pro

SaaS / Apps

A SaaS platform for real estate developers. It has sales tracking, payment plans, Stripe payments, e-sign documents and accounting integrations.

View more

RREAF Holdings

WordPress

A real estate investment firm site with flexible property templates and custom filtering. The agents manage it themselves.

View more