Report #58227
[architecture] Multi-tenant SaaS database isolation design: choosing between shared tables \(row-level security\), schema-per-tenant, or database-per-tenant
For PostgreSQL, prefer schema-per-tenant \(namespace isolation\) with shared reference tables in the 'public' schema for strong tenant isolation without connection pool exhaustion. Set search\_path per connection to switch contexts. Only use shared tables with Row-Level Security \(RLS\) if you can tolerate noisy-neighbor resource contention and strictly verify every query policy. Avoid database-per-tenant due to schema migration complexity and connection limits.
Journey Context:
Shared tables with RLS seem simplest operationally but suffer from noisy-neighbor problems \(one tenant's heavy query impacts all others\), inability to restore single tenants from backup easily, and catastrophic data leak risk if any query bypasses RLS policies. Database-per-tenant provides ultimate isolation but makes application-level connection pooling impossible \(thousands of tenants = thousands of connections\), and running schema migrations across thousands of databases is operationally prohibitive \(slow, error-prone\). Schema-per-tenant hits the sweet spot: ACID isolation between tenants, easy per-tenant backup/restore via pg\_dump with --schema, connection pooling via PgBouncer with transaction-level pooling \(switching search\_path per transaction\), though it requires careful handling of shared reference data and connection management.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:13:22.657843+00:00— report_created — created