The multi-tenancy choice is the single architectural decision that follows your SaaS forever. This guide compares RLS vs schema-per-tenant on Postgres (plus the database-per-tenant option) for founders, CTOs and engineers deciding how to isolate customer data. We've shipped both Row Level Security (RLS) and schema-per-tenant approaches and helped customers migrate between them. Here's what we've learned, with numbers: the trade-offs, our internal benchmarks, and a decision framework you can apply to your own product.
Key takeaways
RLS (shared schema,
tenant_idcolumn on every table) is simpler operationally and scales better at small/mid customer counts.Schema-per-tenant isolates data better, simplifies backups and migrations per customer, and wins for highly regulated or large-customer scenarios.
A third option, database-per-tenant, is overkill for most and underrated for the cases it does fit.
Don't switch mid-flight unless you have to. The migration costs are real.
Why the multi-tenancy model matters so much
Get this wrong and you'll either spend years patching the architecture or fundamentally migrate the database, both expensive. Get it right and the rest of your engineering is freed up to focus on product. The model you pick shapes every query, every migration, every backup and every conversation with a compliance reviewer, which is why it deserves a deliberate decision rather than a default.
The three Postgres multi-tenancy architectures, in one paragraph each
RLS (Row-Level Security)
One database, one schema. Every table has a tenant_id column. Postgres RLS policies enforce that every query only returns rows where tenant_id = current_setting('app.tenant_id'). Your app sets the tenant ID on every connection.
In plain Postgres, the pattern looks like this for a single table:
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON invoices
USING (tenant_id = current_setting('app.tenant_id')::uuid);
-- per request, before any query runs
SET app.tenant_id = '6f1c...';
Schema-per-tenant
One database, multiple schemas: tenant_alpha, tenant_beta, tenant_gamma. Each tenant's tables live in their own schema. The app routes queries to the right schema by setting search_path per connection.
-- per request, pick the tenant's schema
SET search_path TO tenant_alpha;
SELECT * FROM invoices; -- resolves to tenant_alpha.invoices
Database-per-tenant
One database per tenant. Each customer gets their own Postgres instance (or logical database within a cluster). Highest isolation, highest operational cost.
Operational trade-offs: RLS vs schema-per-tenant vs database-per-tenant
Concern | RLS | Schema-per-tenant | DB-per-tenant |
|---|---|---|---|
Migration ease | Easy (one schema) | Hard (run per tenant) | Hard (run per tenant) |
Backup granularity | Coarse | Per tenant | Per tenant |
Per-tenant data export | Hard | Easy | Trivial |
Noisy-neighbor risk | High | Medium | None |
Operational complexity | Low | Medium | High |
Cost at 1000 tenants | Low | Medium | High |
Compliance / "data isolation" story | Weakest | Strong | Strongest |
Read the table as a set of trade-offs rather than a scorecard: the rows where RLS looks weakest (backup granularity, per-tenant export, isolation story) are exactly the rows where the other two models earn their higher operating cost.
Real benchmarks: RLS vs schema-per-tenant on the same workload
We ran an identical workload on both in our internal load test: 100 tenants, 10M rows total, 50 concurrent users. The query was a typical SELECT with a tenant filter plus a join.
Metric | RLS | Schema-per-tenant |
|---|---|---|
P50 query latency | 12ms | 11ms |
P99 query latency | 84ms | 47ms |
Index size | 2.4GB | 1.9GB |
Backup time (full) | 18min | 18min |
Backup time (single tenant) | N/A | 14sec |
Migration time (alter column) | 22sec | 11min (loop) |
The big wins for RLS: simpler migrations. The big wins for schema-per-tenant: per-tenant operations (backup, export, restore). Median latency is close to identical; the gap shows up in the tail (P99) and in anything you need to do for one customer at a time.
When RLS is the right choice
You have hundreds to low-thousands of tenants.
Tenants are similar in shape and size (no enterprise outlier crushing the cluster).
Compliance does not require physical isolation.
You're early-stage and operational simplicity is a multiplier.
When schema-per-tenant is the right choice
You have tens to hundreds of tenants, growing slowly.
Some tenants are very large (single tenant > 10% of total data).
Per-tenant restores and exports are a frequent operation.
Compliance frameworks want named-schema isolation.
If audits are on your roadmap, our SOC 2 readiness guide for Indian SaaS covers how the isolation story gets examined in practice.
When database-per-tenant is the right choice
Enterprise customers explicitly demand it (sometimes a contract clause).
Regulatory requirements force physical isolation (rare; usually schema is enough).
A single tenant's data volume justifies its own cluster.
A quick decision framework
Your situation | Start with |
|---|---|
Early or mid-stage B2B SaaS, similar tenants | RLS, with rigorous policy tests |
Consumer SaaS | RLS, almost always |
Mid-to-late stage with clear enterprise tier requirements | Schema-per-tenant from day one, if you can |
Contract or regulator demands physical isolation | Database-per-tenant for those tenants |
Free/standard tier plus an enterprise tier | RLS for the first, schema-per-tenant for the second |
Still weighing the database itself? See PostgreSQL vs MongoDB for multi-tenant SaaS, and for the application layer around it, modular monolith vs microservices.
Common multi-tenancy pitfalls
The second is RLS without proper testing of the policies. A single policy oversight means a tenant-data leak. Build automated tests that try to access cross-tenant data and confirm they fail.
-- integration test: act as tenant A, try to read tenant B
SET app.tenant_id = '<tenant-a-id>';
SELECT count(*) FROM invoices
WHERE tenant_id = '<tenant-b-id>';
-- expected: 0. Any other result is a failed test.
What we recommend
For most B2B SaaS in early or mid stage: start with RLS, write rigorous policy tests, and plan for schema-per-tenant only if a specific customer or compliance need forces it. For mid-to-late-stage with clear enterprise tier requirements: schema-per-tenant from day one if you can. For consumer SaaS: RLS, almost always. Once the model is in place, our post-launch SaaS checklist covers what to keep an eye on as tenants grow.
FAQs
Can we mix RLS and schema-per-tenant?
Yes: RLS for the free/standard tier, schema-per-tenant for the enterprise tier. It's complexity, but it's a sensible scaling pattern.
What about Postgres extensions like pg_tenant?
Useful but immature; we use plain RLS for production-critical paths.
Does RLS impact performance?
Mildly, typically 5-10% overhead on indexed queries. Negligible if your indexes include tenant_id.
How do we test RLS policies?
Integration tests that explicitly try cross-tenant access and assert they fail.
Talk to Techpuvi about complex web applications. We've shipped both architectures and migrated between them, and our complex web applications team can help you choose and build the right one.
