Multi-Tenant SaaS Architecture: Database Strategies, Scale and the Real Trade-Offs
Choosing your multi-tenancy strategy on day one shapes the next 5 years of your SaaS. The wrong choice surfaces as a 6-month migration project at the moment your sales team can least afford one. This guide is an opinionated walk-through of the three main strategies (shared database, schema-per-tenant, database-per-tenant) with the performance numbers, isolation guarantees and migration paths we use at Alher Tech to architect SaaS that scales.
The Three Strategies
- Shared database, shared schema (row-level): All tenants live in the same tables. Every row has a tenant_id. Cheapest to build, cheapest to operate at low tenant count, but isolation depends entirely on disciplined query writing.
- Shared database, schema-per-tenant: Each tenant gets a schema in the same database. Stronger isolation than row-level, less ops than DB-per-tenant. The right middle ground for most B2B SaaS up to 1,000-3,000 tenants.
- Database-per-tenant: Each tenant gets their own database (or cluster). Strongest isolation, easiest to provide data residency, hardest to operate. Right for enterprise SaaS or compliance-heavy verticals.
When Each Wins
Performance Numbers (PostgreSQL, 2026)
Real numbers from production systems we've shipped. Your mileage will vary but these are the order-of-magnitude bounds:
| Strategy | Practical tenant ceiling | Per-tenant migration | Backup granularity |
|---|
| Row-level (shared) | ~5,000 tenants per cluster | Single transaction, all tenants | All-or-nothing |
| Schema-per-tenant | ~3,000 schemas per DB | Per-tenant via search_path | Per-schema dump possible |
| DB-per-tenant | ~200-500 DBs per cluster, then shard | Per-DB | Per-DB at any time |
Shared row-level can scale further with sharding, but you cross a complexity threshold at ~5K tenants where schema-per-tenant becomes simpler operationally.
Isolation: What Each Actually Guarantees
- Row-level isolation: A bug in your WHERE clause leaks tenant data. Most teams enforce via Postgres Row-Level Security (RLS), which sets a policy that filters by tenant_id automatically. Strong if used disciplinedly.
- Schema-level isolation: Cross-tenant access requires explicit cross-schema queries. Easier to enforce in code review. Per-tenant connection strings or search_path settings prevent accidents.
- Database-level isolation: Network-level segmentation. Different credentials, different connection pools, different physical files. Strongest possible isolation short of separate clusters.
- Compliance perspective: HIPAA, PCI, SOC 2 don't mandate DB-per-tenant, but auditors raise fewer questions about it. The cost is operational; the benefit is audit-time speed.
The Migration Trap
If you start with row-level and grow past 1,000 tenants with one or two enterprise customers asking for data residency, you'll need to migrate. The migration costs:
- Schema-aware tenant_id refactoring across 100K+ lines of code: 4-12 weeks of senior engineer time
- Migration scripts to split tenants into schemas without downtime: 2-6 weeks
- Re-doing every connection pool, every monitoring dashboard, every analytics query
- Often a 6-month project that delivers zero new business value
- Cost: $200K – $800K depending on scale and team
If you have any indication that enterprise customers will demand isolation, start with schema-per-tenant from day one. The marginal complexity is small; the migration cost later is enormous.
Practical Architecture for B2B SaaS
The architecture we default to in 2026 for B2B SaaS:
- PostgreSQL with schema-per-tenant. RLS as a backstop on shared tables (auth, billing).
- Single application instance, dynamic search_path per request based on authenticated tenant.
- Connection pooling via PgBouncer with transaction-level pooling (RDS Proxy on AWS).
- Per-tenant feature flags via PostgreSQL JSON column on a tenant table.
- Migrations run per-tenant via a controlled rollout script (10% → 50% → 100% over hours).
- Backup: WAL streaming + per-schema logical dumps for tenant-level point-in-time restore.
- Sharding plan documented before you need it. When tenant count or DB size hits the threshold, shard tenants across DBs by tenant_id hash.
Common Mistakes
- Starting with DB-per-tenant 'because enterprises will ask'. They might. Until then you're paying ops tax for nothing.
- Row-level without RLS. Bug in code = leak. Enable RLS even if your codebase 'always passes tenant_id'.
- Per-tenant migrations applied serially across 5,000 tenants mean 4-hour deploys. Use parallel scripts with safety controls.
- Cross-tenant aggregation queries on the main DB. They lock things you don't expect. Replicate to an analytics DB.
- Storing tenant config in code. Tenant onboarding requires deploys. Move it to the DB.
Choose for the Customer Profile, Not the Demo
Multi-tenancy is the most architecturally consequential decision in a SaaS. Pick based on the customers you'll actually serve, including the enterprise ones two years out.
Schema-per-tenant on PostgreSQL is the right answer for most B2B SaaS in 2026. Default there unless you have specific reasons to go either lower (early-stage SMB) or higher (regulated enterprise).
Frequently asked questions
Should I start with DB-per-tenant?
Only if your first customers are regulated enterprises (HIPAA, banking, defense). Otherwise the ops overhead delays product delivery for benefits you may never need.
Is schema-per-tenant Postgres-only?
Best supported on PostgreSQL. MySQL has limited schema support. SQL Server does it well. NoSQL stores (Mongo, Dynamo) handle multi-tenancy differently, typically per-collection or per-table.
How many schemas can PostgreSQL handle?
Practical ceiling is 3-5K schemas before pg_class queries slow noticeably. Some teams run 10K+ with careful tuning. Past that, shard schemas across multiple databases.
What about Row-Level Security?
Use it as a defense in depth on shared tables, not as your primary isolation mechanism. It's a safety net for human error, not the architecture itself.
Can I migrate from row-level to schema-per-tenant later?
Yes, but it's a 6-month project costing $200K-$800K depending on size. If there's a 30%+ chance you'll need to, start with schema-per-tenant.
Related guides