TechdomeVenture Studio
All Insights/System Design

"Multi-tenant SaaS on PostgreSQL: schema or row-level isolation"

Compare database-per-tenant, schema-per-tenant and shared tables with row-level security in PostgreSQL: isolation, cost, migrations, noisy neighbors, onboarding and reporting.

Techdome Engineering
Techdome EngineeringEngineering Team
Oct 15, 20268 min read
Verified Architecture
"Multi-tenant SaaS on PostgreSQL: schema or row-level isolation"

For most SaaS products, shared tables with a tenant ID and PostgreSQL row-level security (RLS) are the best starting point, because they are cheap to run and fast to onboard. Schema-per-tenant is a middle path when you need stronger separation and can live with heavier migrations. Database-per-tenant gives the hardest isolation and costs the most to operate, so it usually fits a small number of large or tightly regulated customers.

The right choice depends on how strong the isolation must be, how many tenants you expect, and how you plan to run migrations and reporting.

Why this choice matters

In a multi-tenant architecture, many customers share one running application. The database is where a mistake hurts most, because one missing filter can show one customer's data to another.

PostgreSQL supports all three models well, so the decision is about trade-offs, not capability.

The three models side by side

DimensionDatabase per tenantSchema per tenantShared tables + RLS
IsolationStrongest, physicalGood, via schema permissionsLogical, enforced by the database
CostHighestModerateLowest
MigrationsOnce per database, partial failuresOnce per schema, scripted loopOne change
Noisy neighborsBest containmentWeak, shared instanceWeakest
OnboardingSlowest, provision firstFast, schema from templateFastest, an insert
Cross-tenant reportingHardest, needs a warehouseWorkable with union viewsEasiest

Database per tenant

Each tenant gets its own database, and sometimes its own server. Credentials, backups and restores are separate, and a bug in one query cannot cross a database boundary. The cost is overhead per database, small tenants that waste capacity, and migrations you must run for every tenant while handling partial failures. PostgreSQL cannot join across databases in one query, so cross-tenant analytics needs an export pipeline.

Schema per tenant

One database, one schema per tenant, with identical tables in each. A wrong search path setting is the classic failure. Thousands of schemas mean thousands of copies of every table and index in the system catalog, which can slow tooling and backups, and long migrations multiply by tenant count.

Shared tables with row-level security

One set of tables with a tenant_id column on every row. RLS policies make the database itself filter rows by tenant. Once a policy is on, a query that forgets its WHERE tenant_id = ... clause still returns only that tenant's rows. The trade-off is performance isolation: one tenant's heavy query competes with everyone else's, and a very large tenant can skew table statistics.

Getting RLS right

RLS fails quietly if it is set up carelessly. A request should flow like this:

  1. 01Authenticateresolve the tenant
  2. 02Set contextper request or transaction
  3. 03Querypolicy filters rows
  4. 04Resetclear before pool return
  1. Enable RLS on every tenant-scoped table and write a policy that compares the row's tenant ID with a value from the current session.
  2. Set that session value per request or per transaction, and reset it when the connection returns to a pool.
  3. Connect the application as a role that does not own the tables and does not have the bypass attribute.
  4. Index tenant_id, usually as the first column of composite indexes.
  5. Write tests that try to read tenant B's data while authenticated as tenant A.

Treat RLS as a safety net in addition to application-level access control such as RBAC, not a replacement for it.

  • RLS enabled on every tenant-scoped table
  • Application role is not a table owner and cannot bypass policies
  • Tenant setting reset when a connection returns to the pool
  • tenant_id indexed, usually first in composite indexes
  • A test proving tenant A cannot read tenant B

How to decide

Ask these questions in order:

  1. Do any customers require physical separation, their own encryption keys or a dedicated backup? If yes, give those customers their own database and keep everyone else on a shared model.
  2. How many tenants do you expect? A very large number of small tenants points to shared tables. A few dozen large ones make schemas or databases realistic.
  3. How uneven is tenant size? A few very large tenants alongside many small ones suggests a hybrid: shared tables by default, with a large tenant moved out when it needs it.
  4. How will you report across tenants? If you need cross-tenant analytics, favor shared tables or plan the warehouse pipeline early.

How this looks at Techdome

Our US and UK telehealth platform for the GLP-1 space is a multi-tenant clinical operating platform on PostgreSQL, serving 38 clinic tenants. It was built with HIPAA and UK GDPR architecture from day zero, so tenant separation sits alongside access control and auditing in the design rather than being added later.

For healthcare data, the isolation decision also feeds your compliance story, because reviewers and customers will ask how one clinic's records are kept from another. See healthcare software and HIPAA and our web and app development work for more on how we approach this.

Takeaways

  • Shared tables with RLS give the best cost and speed for most SaaS products, with database-enforced filtering as a safety net.
  • Schema-per-tenant suits moderate tenant counts but multiplies migration work.
  • Database-per-tenant gives the hardest isolation at the highest operational cost, so reserve it for customers who need it.
  • Choose based on isolation requirements, tenant count, size variance and reporting needs, and keep a hybrid path open.
  • Test cross-tenant access explicitly. Do not assume the policy works.

Have a project like this? Talk to our engineers.

FAQ

Questions readers ask

Is row-level security enough to isolate tenants?

It is a strong safeguard because the database enforces it even when application code forgets a filter. It does not give physical separation or per-tenant performance limits, so some customers may still need a dedicated database.

Can I switch models later?

Yes, but it takes real work. Moving a tenant from shared tables to its own database means copying its rows, repointing connections and testing, which is why a tenant-resolving layer in your code helps early on.

Does schema-per-tenant scale to thousands of tenants?

It can become hard to manage at that scale. Catalog size, migration time and backup tooling all grow with the number of schemas, so test with a realistic tenant count before committing.

How do I handle noisy neighbors on shared tables?

Add per-tenant rate limits, query timeouts and sensible indexes, and watch for outliers. If one tenant keeps dominating, move it to a dedicated instance.

What about reporting across tenants in a database-per-tenant setup?

You usually copy data from each database into a central store built for analytics. Plan that pipeline from the start, since PostgreSQL cannot query across separate databases directly.

Continue reading

More foundry teardowns

View all
The Techdome Blueprint: How We Build & Launch Software Ventures in 8 Weeks
Studio ArchitectureAugust 2026

The Techdome Blueprint: How We Build & Launch Software Ventures in 8 Weeks

Rahul Joshi
Rahul JoshiChief Executive Officer
How long does it take to build an MVP? A realistic timeline
Engineering PracticeOct 15, 2026

How long does it take to build an MVP? A realistic timeline

Techdome Engineering
Techdome EngineeringEngineering Team
"PCI DSS for startups: keep card data out of your systems"
Engineering PracticeOct 15, 2026

"PCI DSS for startups: keep card data out of your systems"

Techdome Engineering
Techdome EngineeringEngineering Team
API testing explained: types, what to automate, and tools
Engineering PracticeOct 15, 2026

API testing explained: types, what to automate, and tools

Techdome Engineering
Techdome EngineeringEngineering Team
"Automating mortgage back-office work with n8n"
n8n AutomationOct 15, 2026

"Automating mortgage back-office work with n8n"

Techdome Engineering
Techdome EngineeringEngineering Team
The DevOps lifecycle, from commit to production
Engineering PracticeOct 15, 2026

The DevOps lifecycle, from commit to production

Techdome Engineering
Techdome EngineeringEngineering Team
Fixed price vs time and materials for a software project
Engineering PracticeOct 15, 2026

Fixed price vs time and materials for a software project

Techdome Engineering
Techdome EngineeringEngineering Team
A practical HIPAA checklist for app architecture
Healthcare AIOct 15, 2026

A practical HIPAA checklist for app architecture

Techdome Engineering
Techdome EngineeringEngineering Team
"n8n vs Zapier vs Make: which one for business automation"
n8n AutomationOct 15, 2026

"n8n vs Zapier vs Make: which one for business automation"

Techdome Engineering
Techdome EngineeringEngineering Team
Progressive web apps or native apps for clinical and field tools
System DesignOct 15, 2026

Progressive web apps or native apps for clinical and field tools

Techdome Engineering
Techdome EngineeringEngineering Team
RAG vs GraphRAG: when a knowledge graph is worth it
AI & Machine LearningOct 15, 2026

RAG vs GraphRAG: when a knowledge graph is worth it

Techdome Engineering
Techdome EngineeringEngineering Team
React or Next.js: what to choose for a new product
Our StackOct 15, 2026

React or Next.js: what to choose for a new product

Techdome Engineering
Techdome EngineeringEngineering Team
"Self-hosted n8n in production: queue mode, workers and Redis"
n8n AutomationOct 15, 2026

"Self-hosted n8n in production: queue mode, workers and Redis"

Techdome Engineering
Techdome EngineeringEngineering Team
Staff augmentation vs dedicated team vs outsourcing
Engineering PracticeOct 15, 2026

Staff augmentation vs dedicated team vs outsourcing

Techdome Engineering
Techdome EngineeringEngineering Team
"Types of AI agents and when each one fits"
AI & Machine LearningOct 15, 2026

"Types of AI agents and when each one fits"

Techdome Engineering
Techdome EngineeringEngineering Team
"WCAG 2.2 AA: what to audit and how to test"
Engineering PracticeOct 15, 2026

"WCAG 2.2 AA: what to audit and how to test"

Techdome Engineering
Techdome EngineeringEngineering Team
+
+
+
+
System DesignOct 7, 2026

Vector Database Evolution: Production RAG Beyond Embeddings

Rahul Joshi
Rahul JoshiChief Executive Officer
Optimizing Next.js 15 Monorepos for Sub-Second TTFB at Scale
Studio ArchitectureSeptember 2026

Optimizing Next.js 15 Monorepos for Sub-Second TTFB at Scale

Rahul Joshi
Rahul JoshiChief Executive Officer
Autonomous Multi-Agent Orchestration: Production Patterns Beyond LangChain
Studio ArchitectureSeptember 2026

Autonomous Multi-Agent Orchestration: Production Patterns Beyond LangChain

Rahul Joshi
Rahul JoshiChief Executive Officer
Engineering Zero-Trust HIPAA Compliant AI Architectures for Telemedicine
Healthcare AIAugust 2026

Engineering Zero-Trust HIPAA Compliant AI Architectures for Telemedicine

Rahul Joshi
Rahul JoshiChief Executive Officer
Production n8n Architecture: Hardened Patterns for Enterprise Pipelines
n8n AutomationAugust 2026

Production n8n Architecture: Hardened Patterns for Enterprise Pipelines

Rahul Joshi
Rahul JoshiChief Executive Officer