Security
Multi-Tenancy Basics: Keeping Customer Data Separated in Your SaaS
Shared database, shared schema — or stronger isolation? How SaaS apps keep tenant data separated, the query-scoping discipline that prevents leaks, and when to upgrade isolation.
By AI Production Partner · · 3 min read
The stakes: one bug, another customer's data
Multi-tenancy is the property that customer A can never see customer B's data — and in most SaaS apps it hangs on every single query remembering a WHERE clause. Miss the tenant scope once, anywhere, and you have a cross-tenant leak: the breach category that ends enterprise deals on the spot. AI-generated code misses it regularly, because tenant scoping is exactly the kind of cross-cutting rule that per-prompt generation doesn't hold in mind.
The standard model and its discipline
Shared database, shared schema, tenant_id column on every tenant-owned table is the right default for nearly all SaaS: cheap, simple, scalable far beyond most companies' needs. The discipline that makes it safe: tenant scoping enforced centrally (ORM global scopes, repository layers, or Postgres row-level security keyed to the session's tenant), never re-written by hand per query; tenant_id validated from the session, never from client input; and cross-tenant tests that actively try to read the other customer's records.
Postgres RLS as a backstop is worth singling out: even when application code forgets, the database refuses. Belt and suspenders, for the failure that must not happen.
When to upgrade isolation
Schema-per-tenant or database-per-tenant buy stronger isolation at real operational cost (migrations × tenants, connection management) — justified when enterprise contracts or regulation demand it, and rarely before. The pragmatic path: shared schema with RLS now, isolation upgrades priced into enterprise tiers later, where the customers requiring them pay for them.
Tenant isolation review — including the adversarial cross-tenant tests — is a fixture of our security audits for anything B2B.