Report #39309
[architecture] Choosing data isolation strategy for multi-tenant SaaS \(database-per-tenant vs schema-per-tenant vs row-level security\)
Use PostgreSQL Row-Level Security \(RLS\) with a tenant\_id column for most SaaS; reserve schema-per-tenant only for tenants requiring heavy schema customization; avoid database-per-tenant due to connection pool and migration overhead.
Journey Context:
Database-per-tenant provides maximum isolation and easy per-tenant backup/restore, but connection pools exhaust quickly \(thousands of tenants = thousands of connections\) and schema migrations must run against every database sequentially, becoming operationally impossible at scale. Schema-per-tenant shares a connection pool and allows some customization, but PostgreSQL catalogs bloat with thousands of schemas, slowing metadata queries and backups. RLS enforces tenant isolation at the database layer via policies \(e.g., USING \(tenant\_id = current\_setting\('app.current\_tenant'\)::int\)\), allowing a single shared schema with optimal connection usage and fast migrations. The complexity lies in ensuring tenant\_id is indexed and policies don't disable index usage, and connection pooling middleware must set the tenant context correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:27:16.861574+00:00— report_created — created