Topic 211 / Advanced
Multi-tenant architecture: tenant isolation models, quotas, noisy neighbors
Chapter 13.3 · Multi-Tenant Architecture
What and why
Resource-level authorization (→ 163) proves that one user cannot read another user's resources inside a single tenant; multi-tenancy asks the same question one layer up — can tenant A's data, load, or failures ever reach tenant B, no matter what code runs, when both run on shared infrastructure to keep costs down. Multi-tenant architecture is the set of isolation models and operational controls that answer that question deliberately instead of by accident. Builds on: → 163 (RBAC and ABAC, resource-level authorization).
Diagram
| Isolation model | Isolation | Cost per tenant | Operational complexity |
|---|---|---|---|
Shared schema (tenant_id column) |
Lowest — one missing filter leaks data | Lowest | Lowest — one schema to migrate |
| Schema-per-tenant | Medium — separate namespace, same engine | Medium | Higher — N schemas to migrate |
| Database-per-tenant | Highest — separate storage and blast radius | Highest | Highest — N databases to provision and monitor |
How it works
- Shared schema: every table carries a
tenant_idcolumn; every query must filter by it, enforced centrally (a default scope, row-level security) so isolation doesn't depend on every engineer remembering aWHEREclause — a missing filter here is the worst-case isolation failure, a direct leak between tenants. - Schema-per-tenant: the same database engine, but each tenant gets its own schema — isolation becomes structural rather than a query-time filter, at the cost of running migrations once per schema instead of once total.
- Database-per-tenant: each tenant gets a fully separate database; a crash, a slow query, or a runaway tenant is contained to that tenant's own database, at the highest cost and operational load.
- Tenant context propagation: the tenant ID must flow through the entire call path — auth token claim, service-to-service calls, database query, background job — because isolation enforced only at the entry point is not isolation; a background job that forgets which tenant it's running for is a common place this breaks.
- Quotas (→ 96) bound a tenant's resource consumption — requests per second, storage, concurrent jobs — using the same algorithms rate limiting already teaches, applied per tenant instead of per user.
- Noisy neighbors: without quotas or isolation, one tenant's traffic spike or large batch job degrades shared infrastructure for every other tenant — shared schema and shared compute are the most exposed, database-per-tenant the least.
- Per-tenant observability and billing: metrics, logs, and traces tagged with tenant ID let a noisy-neighbor incident be attributed to the tenant causing it, and let usage-based billing be computed from the same data.
Practical example
(illustrative). A platform with 1,000 tenants on shared schema finds that 5 "whale" tenants generate most of its database load. Moving only those 5 to dedicated databases removes their load from the shared schema entirely, while the other 995 smaller tenants stay on shared schema at low cost — a mixed strategy driven by measured load rather than isolating all 1,000 tenants uniformly at the most expensive level.
When to use it
- Use when: many customers are served from shared infrastructure and full dedicated deployments per customer aren't economical.
- Avoid when: regulation or compliance mandates a dedicated database regardless of cost, or tenant count is small enough that database-per-tenant is simpler to operate correctly than building shared-schema isolation well.
- Failure scenarios: a missing
tenant_idfilter leaking data across tenants; a large tenant's batch job starving shared compute for everyone else; tenant context lost across an async boundary so a background job can't tell whose data it's touching. - Simpler alternative: one dedicated deployment per customer, when customer count is small and each pays enough to justify it — multi-tenancy is a cost optimization, not a requirement.
Practice
(Decision kind — judge scenarios and defend the choice; 20–30 min, no lab services). Given 5 tenant scenarios varying in size, compliance needs, and load pattern, assign each an isolation model using the isolation/cost/ops table, and justify each choice against "why not database-per-tenant for all of them." Done when every justification names a concrete cost or risk the rejected model would have avoided or caused.
Key takeaway
Multi-tenancy trades isolation for shared-infrastructure cost savings along a spectrum from shared schema to database-per-tenant; quotas and tenant-context propagation are what make the cheaper end of that spectrum safe. Done when you can: pick an isolation model for a given tenant profile and name its specific isolation gap. Used next in → 212 (the same isolation question, applied to the whole stack); Project 20.
References
None — this topic makes no external claims.
Source directory