System Design

Design Multi-Tenant Isolation

Step 1 / 9

Learn system design by building multi-tenant isolation step by step.

The numbers to beat1 placeto enforceautoscoped queries0forgotten filters

In the interview room

How you’d open this design in an interview

Before any boxes: agree what it must do, pin the qualities that shape everything, then build — naming each trade-off as you make it. The walkthrough above is that exact order.

Functional requirements

What it must do — agree on these before drawing a single box.

  • Serve many tenants: run one shared system for all customers while keeping their worlds strictly separate.
  • Scope every query: resolve the tenant at the edge and inject a tenant id that filters all data access automatically.
  • Isolate data: choose per customer along a spectrum — shared table, schema-per-tenant, or database-per-tenant.
  • Isolate performance: per-tenant rate limits and resource caps so a noisy neighbor stays in its own lane.
  • Separate secrets + prove it: a per-tenant encryption key and config, plus a tenant-scoped audit trail.

Non-functional requirements

The qualities that shape the whole design — each one names the mechanism that buys it.

Sharing infrastructure stays economical
One shared gateway, app tier, and store serve every tenant; separation is layered on top rather than forking the system per customer.
No query can ever forget its tenant filter
Resolve the tenant once at the gateway and inject a tenant id the data layer applies to every query by default — enforced centrally, not per-developer.
Match separation to each customer’s trust
An isolation spectrum — shared table by tenant id, schema per tenant, or database per tenant — chosen per the customer’s compliance needs.
One tenant’s spike can’t degrade the rest
Per-tenant quotas — rate limits and resource caps at the gateway — throttle a noisy neighbor to its own budget.
A key leak exposes only one tenant
Encrypt each tenant’s data under its own key, so a compromise is bounded to that customer and crypto-shredding makes deletion a key destroy.
Isolation is provable, not assumed
A tenant-scoped immutable audit trail plus automated cross-tenant access tests in CI that fail if A’s token can read B.

The trade-offs you say out loud

Senior signal isn’t the boxes — it’s naming what you gave up and why it was the right price.

Centrally injected tenant contextover code-reviewing every query for a filter

Humans miss things and one missed filter is a breach. Resolve the tenant once at the edge and the framework scopes every query, so no individual query can forget it.

An isolation spectrum per customerover a database per tenant for everyone

DB-per-tenant is the strongest separation but the heaviest to run — thousands of databases to migrate and back up. Most tenants live happily on a shared, tenant-filtered store; reserve silos for regulated ones.

Per-tenant quotasover auto-scaling more servers on a spike

More capacity doesn’t stop one tenant monopolizing it faster than you can add it, and it makes one customer’s abuse everyone’s cost. Caps throttle the spike to its own budget instead.

A key per tenantover one shared encryption key

One shared key means a single leak exposes every tenant at once. A per-tenant key bounds a compromise to one customer and turns deletion into destroying a key (crypto-shredding).

Automated cross-tenant tests + auditover trusting that the code is careful

Isolation you can’t verify is isolation you can’t trust, and a subtle leak can be silent. CI tests that A’s token can never read B turn "we’re sure" into a property checked on every deploy.

What this teaches

Learn system design by building multi-tenant isolation step by step. An interactive guide covering tenant context propagation, the data-isolation spectrum (row-level, schema-per-tenant, database-per-tenant), preventing noisy neighbors with per-tenant quotas, per-tenant secrets and encryption, and audit plus isolation testing — how a forward deployed engineer serves many customers from one system without leaking data between them.

Key takeaways

  • A shared gateway + store is the efficient core; the discipline is making sharing safe.
  • Resolve the tenant at the edge and inject a tenant id that scopes every query automatically.
  • Choose the isolation model per customer: shared+tenant-id, schema-per-tenant, or DB-per-tenant.
  • Per-tenant quotas isolate performance so a noisy neighbor can’t degrade everyone.
  • Per-tenant encryption keys bound a key compromise to one tenant and enable clean deletion.
  • A per-tenant audit trail plus automated cross-tenant tests make isolation provable.

Concepts covered

  • What is multi-tenant isolation?
  • Many customers, one system
  • Inject tenant context
  • The isolation spectrum
  • Per-tenant quotas
  • Per-tenant keys + config
  • Audit + isolation testing

Design Multi-Tenant Customer Isolation — read the full walkthrough as text

the same steps, decisions & trade-offs, for reading, reference & search

The big idea

What is multi-tenant isolation?

You serve many customers (tenants) from one system to keep it efficient and cheap to operate. But each tenant’s data, performance, and configuration must be strictly separated — tenant A must never see tenant B’s data, and one customer’s bad day must not become everyone’s outage. One missing filter is a cross-tenant data leak, the worst kind of bug.

Inject a tenant context on every request, scope all data access to it, choose an isolation model matched to the customer’s trust needs, cap noisy neighbors with per-tenant quotas, encrypt with per-tenant keys, and prove it with a tenant-scoped audit. Many customers, one system, strictly separated.

How to read this: We add one piece at a time, problem then fix, and the diagram grows. Hit Begin.

Step 1 · The skeleton

Many customers, one system

The naive version: all tenants hit the same Gateway and read from the same shared store, with nothing distinguishing them. It’s efficient — and it’s a data breach waiting to happen, because any query could return any tenant’s rows.

Stand up a shared Gateway and store serving all tenants. This is the efficient core of multi-tenancy; every step from here adds the separation that makes sharing safe.

Shared is efficient, and dangerous: Sharing infrastructure across tenants is why SaaS is economical. The entire discipline of multi-tenancy is making that sharing safe — data, performance, and config all separated.

Step 2 · Who is this?

Inject tenant context

If each piece of code has to remember to filter by the right customer, someone eventually forgets — and a single unscoped query leaks one tenant’s data to another. You can’t rely on discipline for something this catastrophic.

Design decision: A single query that forgets to filter by tenant leaks data across customers. How do you prevent that reliably?

The call: Resolve the tenant at the gateway and inject a tenant id that scopes every query automatically. — Authenticate, resolve the tenant, and stamp the tenant id into a request context that the data layer applies to every query by default. Isolation is enforced centrally, so no individual query can forget it.

Add a Tenant Resolver: authenticate the user, map them to a tenant, and inject the tenant id into the request context. The data layer applies it to every query automatically, so isolation is enforced by the framework, not by each developer remembering.

Enforce context centrally: Resolve the tenant once, at the edge, and thread it through automatically. The safest filter is the one no query can forget because the framework adds it for you.

Step 3 · Where does data live?

The isolation spectrum

A shared table filtered by tenant id is cheap and easy to operate, but one bug crosses tenants and a regulated customer may reject "your data sits in the same table as everyone else’s." Stronger isolation costs more to run. There’s no single right answer.

Design decision: How strongly should you isolate tenant data — shared table, schema-per-tenant, or database-per-tenant?

The call: Choose per the customer: shared+tenant-id, schema-per-tenant, or DB-per-tenant. — It’s a spectrum. A shared table filtered by tenant id is cheapest and scales to many small tenants; a schema or database per tenant gives stronger separation for regulated or high-value customers. Match the model to each tenant’s trust and compliance needs.

Pick the Isolation Model per customer along a spectrum: a shared table filtered by tenant id (cheapest, most tenants), a schema per tenant (stronger, still shared DB), or a database per tenant (strongest, most operational cost). Match strength to the customer’s trust and compliance needs.

Isolation is a dial, not a switch: Shared → schema → dedicated database trades efficiency for separation. Most tenants live happily on a shared, tenant-filtered store; regulated or high-value ones justify a silo.

Step 4 · The noisy neighbor

Per-tenant quotas

Data isolation isn’t enough. One tenant sends a flood of traffic or runs a monster query, consuming the shared app and database capacity — and every other tenant slows down or errors. Isolation has to cover performance, not just data.

Design decision: One tenant’s traffic spike degrades every other tenant on the shared infrastructure. How do you contain it?

The call: Enforce per-tenant rate limits and resource quotas. — Cap each tenant’s request rate and resource use (connections, query cost) so one customer’s spike is throttled to its own budget instead of consuming the shared pool. The noisy neighbor is contained to its own lane.

Add Per-Tenant Quotas: rate limits and resource caps applied at the gateway per tenant, so one customer’s spike is throttled to its own budget instead of draining the shared pool. Performance isolation, alongside data isolation.

Isolate performance too: A noisy neighbor is a tenant that eats shared capacity. Per-tenant rate limits and resource caps keep one customer’s bad day inside its own lane.

Step 5 · Separate secrets

Per-tenant keys + config

If every tenant’s data is encrypted under one shared key, a single key compromise exposes everyone, and you can’t cleanly delete or export one tenant. And tenants often need their own configuration — features, limits, branding.

Give each tenant its own encryption key and its own configuration. Encrypting a tenant’s data under its own key means a key leak exposes only that tenant and enables true per-tenant deletion (drop the key). Per-tenant config lets one system behave differently for each customer.

Per-tenant keys contain the blast radius: One key per tenant means a compromise is bounded to one customer, and "delete tenant" can be as clean as destroying its key. Config-per-tenant makes one system feel bespoke.

Step 6 · Prove it holds

Audit + isolation testing

Isolation you can’t verify is isolation you can’t trust — and a regulated customer will demand evidence. Worse, a subtle bug could be leaking across tenants right now with no visible symptom.

Add a tenant-scoped, immutable Audit trail of who accessed and changed what, per tenant — the evidence compliance requires. And test isolation continuously: automated checks that a tenant A token can never read tenant B data, run in CI. Isolation becomes provable, not assumed.

Verify isolation, don’t assume it: A per-tenant audit trail is both a compliance artifact and a tripwire. Automated cross-tenant access tests turn "we’re sure it’s isolated" into "we prove it on every deploy."

You did it

You just designed multi-tenant isolation.

  • A shared gateway + store is the efficient core; the discipline is making sharing safe.
  • Resolve the tenant at the edge and inject a tenant id that scopes every query automatically.
  • Choose the isolation model per customer: shared+tenant-id, schema-per-tenant, or DB-per-tenant.
  • Per-tenant quotas isolate performance so a noisy neighbor can’t degrade everyone.
  • Per-tenant encryption keys bound a key compromise to one tenant and enable clean deletion.
  • A per-tenant audit trail plus automated cross-tenant tests make isolation provable.
built so tenant A never sees tenant B, not memorized — inject context, isolate data, cap the noisy.
Finished this one? 0 / 65 System Designs done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More System Designs