Report #47915
[architecture] Schema-per-tenant multi-tenancy causes connection pool exhaustion and migration failures at scale
Use PostgreSQL Row Level Security \(RLS\) with shared tables partitioned by tenant\_id; enforce isolation via policy functions and set tenant context per connection using SET app.tenant\_id.
Journey Context:
Schema-per-tenant seems logically clean but creates N×M tables \(N tenants × M entities\), blowing up metadata cache and making migrations O\(N\) time \(altering 10k schemas takes hours\). Database-per-tenant requires connection pooling per DB or expensive reconnection. RLS with shared tables keeps migrations fast \(single DDL\) and connection pools efficient. Critical implementation: RLS policies must be performance-tested with proper indexes on tenant\_id; missing indexes cause sequential scans. Always use 'SET app.tenant\_id = X' on connection reuse to prevent cross-tenant leakage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:54:45.719539+00:00— report_created — created