Tenant Isolation for Multi-Tenant SaaS: How We Enforce and Test It
One codebase serving many paying customers, each sealed off from the others. The isolation is enforced in the database — not just in the API — so one missed check cannot leak customer A's data to customer B.
By Obaid Tariq, Founder & Lead Engineer · Last updated
Obaid founded AI Dev Planner in 2022 and leads engineering on its client projects from Islamabad, Pakistan.
The problem: one missed check leaks data
In a multi-tenant SaaS, every request carries a tenant. If the application is the only thing checking the tenant ID, one missed check — one query, one endpoint, one background job — leaks one customer's data to another. The fix is to enforce isolation where the data lives: in the database itself.
How the architecture works
1. PostgreSQL RLS enforced in the database (`USING` + `WITH CHECK`)
Every tenant table enforces `CREATE POLICY tenant_iso ON records FOR ALL USING (tenant_id = (select (auth.jwt() ->> 'org_id')::uuid)) WITH CHECK (tenant_id = (select (auth.jwt() ->> 'org_id')::uuid))`—blocking both cross-tenant reads and tenant-reassignment writes.
2. Pool vs. Bridge vs. Silo tenancy tradeoffs
Start with Pooled shared tables + RLS for lean USD infra ($150–$450/mo); graduate regulated US healthcare or Fortune 500 buyers to Bridge (per-tenant schema) or Silo (dedicated RDS/VPC) without rewriting application code.
3. Workspaces, RBAC & tenant-level rate limiting
Clerk or WorkOS Organizations map SAML 2.0/OIDC roles to Postgres workspaces, paired with Redis sliding-window rate limits per `tenant_id` so one noisy enterprise tenant never starves others.
4. Stripe billing per tenant
Subscriptions, seats, and usage metering are billed per workspace through Stripe, with idempotent `webhook_events` deduplication and daily reconciliation.
5. Proving isolation in CI
Automated tenant-isolation tests run in GitHub Actions: a test user from Tenant A must never read or mutate Tenant B's rows, under load and inside async background jobs.
What we do not claim
- —Isolation is demonstrated on our own first-party platform and tested in CI — it is not a certification, and we do not claim SOC 2 or any compliance certification.
- —The architecture is the same one described on our SaaS development service page and in our multi-tenant SaaS guide — this page is the architecture-deep version, not a second product.
Stack
| Layer | Choice | Why |
|---|---|---|
| Frontend | Next.js App Router | Server-rendered dashboards with path-prefix or subdomain tenant routing. |
| Language | TypeScript | Typed boundaries between tenants, workspaces and billing. |
| Database | Supabase / PostgreSQL + RLS | Row-level security enforced in the database on every table. |
| Auth & SSO | WorkOS / Clerk / Supabase Auth + RBAC | Organizations, RBAC role mappings, domain-based SAML 2.0 / OIDC SSO and SCIM. |
| Billing | Stripe | Subscriptions, seats and usage billing per workspace. |
| Contracts | Zod | Schema contracts for every API and database boundary. |
| Monorepo | Turborepo | One repository for the platform, with shared types across apps. |
Design target: 100% database tenant isolation under load with zero cross-tenant leaks. This is a design target, not a measured result.
First-party example — our own platform, not a client project
The AI Dev Planner monorepo is our own multi-tenant platform: Next.js App Router, Supabase, PostgreSQL RLS, Zod and Turborepo. It is the system we run ourselves, and the architecture on this page is the architecture it is built on.
Frequently asked questions
What is multi-tenant SaaS architecture?
One codebase serving many paying customers, each sealed off from the others. Isolation is enforced with PostgreSQL row-level security in the database, not just in the application code.
How do you prove tenants cannot see each other's data?
With automated tenant-isolation tests in CI: a test user from one tenant must never see another tenant's rows — including in background jobs, not just in the UI.
How does this differ from your SaaS development service page?
The service page is the commercial offer — what we build, in what time, for what band. This page is the architecture: how isolation is enforced, tested and billed. They describe the same capability from different angles.
How much does a multi-tenant SaaS MVP cost?
A focused SaaS MVP is $25,000–$65,000 over 8–12 weeks; a standard multi-tenant build is $45,000–$75,000. See our SaaS development services for the published tiers.