Multi-Tenant SaaS Architecture: Database Models, Tenant Isolation, and Postgres RLS
What multi-tenancy is, multi-tenant vs single-tenant, the three database models (shared schema, schema per tenant, database per tenant), and tenant isolation with Postgres RLS.

Multi-tenancy means one deployment of your software serves many customers, called tenants, while keeping each customer's data separate. Microsoft's architecture guide puts it this way: "A multitenant solution is a solution used by multiple customers, or tenants. Tenants are distinct from users. Multiple users from a single organization, company, or group form a single tenant." Designing a multi-tenant SaaS comes down to three decisions: how much infrastructure tenants share, how their data is laid out in the database, and what stops one tenant from reading another's data.
This guide covers each decision with Postgres examples, quoting Microsoft's and AWS's architecture guidance and the PostgreSQL documentation, all checked on 4 November 2026 and linked under Sources. We make ShiftFast, a Next.js SaaS starter kit, and we use it as the worked example at the end.
Key takeaways
- A tenant is a customer organization, not a user. Most B2B SaaS products are multi-tenant because sharing infrastructure is far cheaper.
- Postgres offers three database models: a shared schema with a tenant ID column, a schema per tenant, or a database per tenant. Isolation goes up and cost goes down in the opposite direction.
- In a shared schema, every query must filter by tenant. Postgres row-level security can enforce that in the database, but it adds complexity, and Microsoft notes that many multi-tenant solutions don't use it.
- Switching models later is costly, so choose on purpose.
What is multi-tenancy?
A tenant is a customer of your SaaS: usually a company or team, with its own users, data, and billing. A multi-tenant application serves all tenants from shared infrastructure and keeps their data apart. A single-tenant application gives each tenant its own copy.
Microsoft's Azure SQL guidance defines the two at the database level: "Single-tenancy: Each database stores data from only one tenant" and "Multi-tenancy: Each database stores data from multiple separate tenants (with mechanisms to protect data privacy)". It also warns that "Switching to a different model later is sometimes costly."
In a B2B app, the tenant usually maps to an organization or workspace in your auth system, and every user signs in as a member of one or more of them. We cover that side in multi-tenant auth with Clerk Organizations.
Multi-tenant vs single-tenant
Microsoft describes isolation as a spectrum rather than a yes-or-no choice. The trade-offs at each end, from its tenancy models guide:
| Single-tenant | Multi-tenant | |
|---|---|---|
| Data isolation | Each tenant's data is separate, "which reduces the risk of accidental leakage" | Shared, so the application must keep tenants apart |
| Cost | "If a single tenant requires a specific infrastructure cost, 100 tenants probably require 100 times that cost" | "less expensive than using individual resources for each tenant" |
| Operations | One deployment per tenant to update | One deployment to update, but "changes might affect your entire customer base" |
| Performance | Tenants "are unlikely to affect each other's system performance" | Exposed to noisy neighbors |
| Reliability | An outage affects one tenant | "a problem with one component can result in an outage for all of your tenants" |
The noisy neighbor problem "occurs when one tenant's performance is degraded because of the activities of another tenant", in Microsoft's definition, and sharing a resource "inherently carries the risk of noisy neighbor problems that you can't completely avoid."
Most B2B SaaS products start multi-tenant for cost and simplicity, and move individual large or regulated customers onto dedicated infrastructure later if they need it.
Multi-tenant database models in Postgres
AWS's guidance for SaaS on PostgreSQL names three models, silo, bridge, and pool, which map onto the three layouts most teams choose between:
- Database per tenant: AWS's silo model, "A separate PostgreSQL instance or cluster for each tenant", or its "Bridge with separate databases" variant, "A separate database for each tenant in a single PostgreSQL instance or cluster".
- Schema per tenant: AWS's "Bridge with separate schemas", "A separate schema for each tenant in a single PostgreSQL database".
- Shared schema (pool): "Shared tables for tenants in a single instance and schema", with a tenant ID column on every table.
AWS's decision matrix compares them:
| Database per tenant (silo) | Schema per tenant (bridge) | Shared schema (pool) | |
|---|---|---|---|
| Infrastructure cost | "Highest (because nothing is shared)" | "Moderate" | "Lowest" |
| Data isolation | "Best" | "Better", with schema permissions via Postgres roles | "Worse", so you need features "such as row-level security" |
| Rolling out schema changes | "Significant effort", per instance | "Moderate effort", per schema | "Minimal effort" |
| Blast radius of a change | "Single tenant affected" | "Single tenant affected" | "All tenants affected" |
| Per-tenant customization | "Possible" | "Possible" | "Complicated (because all tenants share the same tables)" |
| Tenants affecting each other | "No impact" | "Moderate impact" | "Heavy impact" |
| Best for | "very large and very performance-sensitive tenants" | "Moderate number of tenants with a moderate amount of data" | "Large number of tenants with less data per tenant" |
Shared schema (pool)
Every tenant's rows live in the same tables, and each table has a tenant
column such as org_id. Microsoft's Azure SQL guidance notes that this schema
"must have one or more tenant identifier columns so that the data from any
given tenant can be selectively retrieved", and that it has "the lowest
per-tenant cost" but "necessarily sacrifices tenant isolation". It's the
default for most SaaS products with many small and medium customers.
Schema per tenant (bridge)
Each tenant gets its own Postgres schema with identical tables. Isolation is stronger and per-tenant changes are possible, but every migration runs once per schema. AWS warns that with many tenants the Postgres system catalog can reach "tens of GBs", likely requiring vacuum tuning, that major upgrades can mean "Longer downtime", and that some ORMs cache metadata for every tenant, "leading to high DB connection memory usage". It also notes that this model "suffers from the same noisy neighbor and tenant performance isolation concerns as the pool model."
Database per tenant (silo)
Each tenant gets its own database or instance: the strongest isolation and no noisy neighbors, at the highest cost and operational effort. It suits a few large tenants, tenants with strict compliance needs, or customers who pay for dedicated infrastructure.
Tenant isolation in a shared schema
In the shared-schema model, nothing in the table layout stops a query from returning another tenant's rows. Isolation has to be enforced in your code, in the database, or in both.
Application-level scoping
Every query filters by the current tenant, and the tenant ID comes from the signed-in session, never from the request body or URL:
const { orgId } = await auth()
const rows = await db.select().from(projects).where(eq(projects.orgId, orgId))This is simple and fast with an index on the tenant column. The risk is human:
one missing where clause leaks data across tenants. Code review, shared
query helpers, and tests that sign in as two organizations are the usual
defenses.
Postgres row-level security
Row-level security (RLS) moves the check into the database. AWS's Postgres guidance says "Row-level security (RLS) is required to maintain tenant data isolation in a pooled model with PostgreSQL" and recommends enabling it "on all tables that contain tenant data". How it behaves, per the PostgreSQL docs:
- You turn it on per table with
ALTER TABLE ... ENABLE ROW LEVEL SECURITY. - With RLS on and no policy, "a default-deny policy is used, meaning that no rows are visible or can be modified."
- "Superusers and roles with the
BYPASSRLSattribute always bypass the row security system", and table owners bypass it too unless you useALTER TABLE ... FORCE ROW LEVEL SECURITY.
That last point catches many teams: if your app connects as the same database user that ran the migrations and owns the tables, RLS doesn't apply until you force it or connect as a separate, non-owner role.
The application tells Postgres which tenant is active, and the policy compares against it. AWS's example uses a session setting:
CREATE POLICY tenant_isolation_policy ON tenant
USING (tenant_id = current_setting('app.current_tenant')::UUID);Two cautions from the sources. AWS notes that session variables "may be incompatible with server-side connection pooling such as pgBouncer". And Microsoft notes that RLS "might affect performance", that you may need extra indexes, and that "Many multitenant solutions don't use row-level security because of those complexities."
Our recommendation, reasoning from the Postgres docs rather than quoting
them: set the tenant per transaction with set_config(..., true) (the
same as SET LOCAL), whose value applies "only during the current
transaction". A pooled connection then can't carry one request's tenant into
the next.
RLS with Drizzle ORM
Drizzle declares policies next to the
table with pgPolicy, and "If you add a policy to a table, RLS will be
enabled automatically." This compiles against Drizzle 0.45:
import { sql } from 'drizzle-orm'
import { index, pgPolicy, pgTable, text, uuid } from 'drizzle-orm/pg-core'
export const projects = pgTable(
'projects',
{
id: uuid('id').primaryKey().defaultRandom(),
orgId: text('org_id').notNull(),
name: text('name').notNull(),
},
(t) => [
index('projects_org_id_idx').on(t.orgId),
pgPolicy('projects_tenant_isolation', {
for: 'all',
using: sql`${t.orgId} = current_setting('app.current_org', true)`,
withCheck: sql`${t.orgId} = current_setting('app.current_org', true)`,
}),
]
)The true passed to current_setting makes it return NULL instead of an
error when no tenant is set, so a query without a tenant sees no rows. Each
request then sets its tenant inside a transaction:
export async function listProjects(orgId: string) {
return db.transaction(async (tx) => {
await tx.execute(sql`select set_config('app.current_org', ${orgId}, true)`)
return tx.select().from(projects)
})
}using filters the rows a query can see, and withCheck rejects inserts and
updates that would write another tenant's ID.
How to choose
- Start with a shared schema if you expect many tenants with modest data each. It's the cheapest to run and the simplest to migrate.
- Add row-level security on top if a cross-tenant leak would be unacceptable and your team can own the database roles and pooling details.
- Use a schema per tenant if tenants need per-tenant customization and you have a moderate number of them.
- Use a database per tenant for a small number of large, sensitive, or contract-bound customers, or offer it as a premium tier on top of a pooled default.
Whichever you pick, put the tenant ID in every table from day one. Moving from a shared schema to dedicated databases for a few tenants later is much easier than adding tenant columns to a schema that never had them.
How ShiftFast does it
ShiftFast uses the shared-schema model, and the tenant is a Clerk
Organization. Its billing table holds one subscription row per organization,
keyed by Clerk's organization ID, and its docs set the rule for every table
you add: an org_id column with an index, and queries that filter by the
orgId Clerk's auth() returns on the server, never by an ID sent from the
browser.
It enforces isolation in the application and doesn't ship row-level security, which keeps database roles and connection pooling simple. If you want the database-level safety net, the Drizzle policy above drops into its schema. The Organizations docs and Build your first feature walk through the pattern, and Clerk vs Better Auth for B2B SaaS compares two ways to manage the organizations themselves.
FAQ
What is a tenant in SaaS?
A customer of your software, usually an organization with several users. In Microsoft's words, "Multiple users from a single organization, company, or group form a single tenant."
Is multi-tenant less secure than single-tenant?
Shared infrastructure means isolation depends on your application or database rules rather than on separate hardware. AWS rates a shared schema's isolation "Worse" than separate schemas or databases, which is why it recommends row-level security for pooled Postgres. Done carefully, multi-tenant systems run safely at very large scale.
What is the noisy neighbor problem?
When one tenant's heavy usage slows the service for others sharing the same resources. Separate databases avoid it; shared schemas need limits and monitoring instead.
Should I use a schema per tenant in Postgres?
It works for a moderate number of tenants that need customization. With many tenants, AWS warns of a very large system catalog, slower major upgrades, and higher connection memory for some ORMs, so most SaaS products prefer a shared schema.
Do I need row-level security for multi-tenancy?
Not strictly; many teams scope every query in the application instead. RLS adds a second layer that catches a forgotten filter, at the cost of managing database roles, policies, and how the tenant is set per connection.
Sources
Checked on 4 November 2026:
- Microsoft: multitenant architecture overview, tenancy models, multitenant SaaS database patterns, storage and data approaches, PostgreSQL in multitenant solutions, noisy neighbor antipattern
- AWS Prescriptive Guidance for multi-tenant PostgreSQL: partitioning models, decision matrix, bridge model, row-level security
- AWS Database Blog: multi-tenant data isolation with PostgreSQL row-level security (May 2020)
- PostgreSQL 18 docs: row security policies, CREATE POLICY, set_config and current_setting, SET
- Drizzle ORM row-level security