Multi-tenancy & isolation
Serve many customers from one system without letting them see, slow or break each other.
A multi-tenant system shares infrastructure across customers. The core question is where to draw the isolation line: a tenant id column in shared tables, a schema per tenant, or a database or whole stack per tenant. Each step up buys isolation and costs operational overhead.
With shared tables, every query must be scoped by tenant. Enforce that in one place, such as database row-level security or a mandatory data-access layer, because relying on every developer to remember a WHERE clause will eventually leak data.
Isolation is also about resources. One tenant's heavy query or import should not degrade the rest, so add per-tenant rate limits, quotas and queue partitioning. Large customers often get dedicated capacity as a paid tier.
Key points
- Choose the isolation level from compliance needs, tenant size and ops budget.
- Enforce tenant scoping centrally, ideally in the database.
- Noisy-neighbour control needs quotas and rate limits per tenant.
- Make it possible to move a tenant to dedicated infrastructure later.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Shared tables + tenant_id | Cheapest, simplest to operate | Strict scoping discipline, noisy neighbours |
| Schema or database per tenant | Strong isolation, per-tenant backup and restore | Migrations and connection counts multiply |
Answer these out loud
- 1Write down how a missing tenant filter could slip into production and the two guards that would catch it.
- 2A single tenant triggers a 10M-row export every hour. Design the controls.
Use this from an agent
Any MCP client, including Grok, can read this lesson. See how to connect.
curl https://engineeros-delta.vercel.app/api/v1/topics/multi-tenancy