Full answer
Compare on the dimensions that decide it:
| Concern | Shared tables + tenant_id | Schema per tenant | Database per tenant |
|---|---|---|---|
| Tenant count it handles well | Up to millions | Hundreds to low thousands | Tens to hundreds |
| Isolation | Logical (RLS, app checks) | Namespace level | Strong, separate catalogs |
| Migrations | One run | One run per schema | One run per database |
| Connection pooling | One pool | One pool, search_path per tenant | Pool per database |
| Cross-tenant analytics | Simple queries | UNION across schemas | Separate pipeline |
| Per-tenant restore or delete | Harder (filtered) | Drop or dump a schema | Drop or dump a database |
| Noisy neighbours | Shared resources | Shared resources | Can be placed on separate servers |
Design details for the shared model: put tenant_id first in composite primary keys and indexes, include it in every foreign key so rows cannot point across tenants, enforce it with RLS and SET LOCAL per transaction, and plan to shard by tenant_id later (for example with Citus) if one server is not enough.
Decide by tenant count, size skew, compliance needs (data residency, dedicated hardware) and team capacity for operations. This is a design item with nothing to run.
Key points
- Shared tables scale to many tenants
- Schemas give middle-ground isolation
- Databases isolate strongly but cost most
- Lead indexes and keys with tenant_id
- Hybrid models are common
Common mistakes
- Schema per tenant with tens of thousands of tenants
- Shared tables without tenant_id in foreign keys
Follow-ups
- How would you move one large tenant to its own database?
- How does Citus distribute by tenant?
Tips
- Compare along fixed dimensions