Every SaaS product eventually has to answer one question: how do you keep each customer's data separate? The choice you make early affects security, cost, performance and how painful your first enterprise deal will be. Here are the three common patterns, with the trade-offs we see in real projects.

1. Shared database, shared schema (row-level isolation)

All tenants live in the same tables. Every row carries a tenant_id, and every query filters on it.

SELECT * FROM invoices WHERE tenant_id = $1 AND status = 'open'; 

Pros

  • Cheapest to run and simplest to deploy
  • One migration updates every tenant
  • Easy cross-tenant analytics for your own team

Cons

  • A single missing WHERE tenant_id = ... leaks data
  • Noisy neighbours can hurt performance
  • Harder to offer per-customer backups or data residency

Make it safer: use PostgreSQL Row-Level Security so the database enforces isolation even if application code forgets.

ALTER TABLE invoices ENABLE ROW LEVEL SECURITY; CREATE POLICY tenant_isolation ON invoices USING (tenant_id = current_setting('app.tenant_id')::uuid); 

2. Shared database, schema per tenant

Each tenant gets its own schema (tenant_a.invoices, tenant_b.invoices) inside one database.

Pros

  • Stronger logical isolation than row-level
  • Per-tenant backup and restore is possible
  • Easy to customise a schema for a large customer

Cons

  • Migrations must run across hundreds or thousands of schemas
  • Connection pooling and ORM support get trickier
  • Does not scale well past a few thousand tenants

3. Database per tenant

Each tenant has a completely separate database.

Pros

  • Strongest isolation, easiest compliance story
  • Per-tenant scaling, backups and data residency
  • No noisy-neighbour problems

Cons

  • Highest infrastructure and operational cost
  • Fleet-wide migrations need solid automation
  • Cross-tenant reporting requires a separate data pipeline

How to choose

Situation Recommended pattern
Early-stage SaaS, many small customers Shared schema + Row-Level Security
Mid-market, some customers need customisation Schema per tenant
Enterprise, regulated industries, data residency Database per tenant

A pragmatic path many teams follow is a hybrid: start everyone on a shared schema with RLS, and move large or regulated customers to dedicated databases when a contract requires it. Design your tenant resolution layer (subdomain, JWT claim or header to tenant id to connection) so that switching a tenant between models is a configuration change, not a rewrite.

Checklist before you ship

  • Tenant id is resolved once, at the edge, and passed through context
  • Database enforces isolation (RLS or separate schemas/DBs), not just app code
  • Background jobs and caches are tenant-aware
  • Logs and metrics are tagged with tenant id
  • You have automated tests that try to read another tenant's data

Written by the engineering team at Codestruk, a software development company in India building custom SaaS applications, web and mobile apps.