Report #95126
[architecture] Multi-tenant architecture choice leading to connection pool exhaustion or inadequate data isolation
Use PostgreSQL Row-Level Security \(RLS\) with shared tables for 10-1000 tenants \(low-moderate isolation needs\); use schema-per-tenant for 1000-50k tenants with strict isolation requirements; avoid database-per-tenant unless regulatory mandate requires it due to connection and operational overhead
Journey Context:
Schema-per-tenant feels safer \(true physical separation\) but kills operations. Each schema requires separate connection pool slots; migrations must run N times \(slow, error-prone\). Query performance degrades with thousands of schemas due to catalog bloat. Database-per-tenant is worse: backup/restore complexity, connection limits \(Postgres max ~100 connections default, pools exhaust fast\). Solution: RLS. Shared tables with \`tenant\_id\` column. Enable \`ROW LEVEL SECURITY\` and create policy \`USING \(tenant\_id = current\_setting\('app.current\_tenant'\)::int\)\`. Application sets tenant context per request. Pros: single connection pool, fast migrations, efficient resource use. Cons: risk of policy bypass bugs \(must set context correctly\), harder to restore single tenant \(need WHERE clause\). Mitigation: test RLS policies with every migration. When to use schema-per-tenant: when you have 10k\+ tenants and need true isolation for compliance \(e.g., each tenant is a large enterprise\). Even then, consider RLS with encryption per tenant \(pgsodium\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:14:58.275870+00:00— report_created — created