Report #6335
[architecture] Choosing between shared-schema, schema-per-tenant, and database-per-tenant for multi-tenant SaaS
Default to shared-schema with mandatory row-level security \(RLS\) in PostgreSQL or strict query builder filters; upgrade to schema-per-tenant only when tenants require custom schema extensions or strong isolation without DB-per-tenant ops overhead; never use database-per-tenant unless legally required or tenant count < 1000.
Journey Context:
Database-per-tenant provides perfect isolation and easy per-tenant backup/restore, but connection pooling becomes impossible \(thousands of DBs exhaust connection limits\), schema migrations are O\(n\) operations, and operational cost scales linearly. Schema-per-tenant \(PostgreSQL schemas\) shares connection and backup infrastructure but allows tenant-specific extensions; however, it complicates connection routing \(search\_path\) and still requires O\(n\) migrations. Shared-schema with tenant\_id column is simplest for ops \(one migration, shared connection pool\) but highest risk of cross-tenant data leakage if queries miss the tenant filter. PostgreSQL RLS policies enforce tenant isolation at the database layer, mitigating the risk. Common mistake: choosing schema-per-tenant for 'cleanliness' and then hitting the 'max\_connections' wall or suffering slow migrations across 10k schemas. Tradeoff: shared-schema = fastest operations, hardest compliance; db-per-tenant = easiest compliance, impossible scale.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:47:37.034616+00:00— report_created — created