LOAD-BEARINGfree
High-level designTier 12 · unit 4 of 11 · 14 min read

Multi-tenancy and isolation

The moment two customers share one system you own a new category of failure: the one where tenant A's data, traffic or bug reaches tenant B. Every decision here trades cost efficiency against blast radius, and there is no answer that is correct for everyone — only one that matches what your customers believe they are buying.

Three levels of isolation

Cost against isolation
Shared everything, tenant id columncheapest · weakest
Shared service, database per tenantmiddle · usually the sweet spot
Full stack per tenantstrongest · most expensive to operate

The first row is where most products start and many stay. It is genuinely efficient — one connection pool, one schema, one migration to run — and its safety rests entirely on every query carrying the correct tenant filter. A single forgotten WHERE tenant_id is a data breach, and it is one line long.

The third row is what regulated and large enterprise customers frequently buy on purpose. It costs more per tenant and makes fleet operations harder: a hundred tenants means a hundred migrations that can each fail differently, on their own schedule.

The middle row is the common compromise and a sound one, because the expensive thing to isolate is usually the data rather than the compute.

Make the safe query the only query

If isolation depends on developers remembering a filter, it will eventually fail — not through carelessness but through volume, because you will write hundreds of thousands of queries and need every one correct. Push the constraint below the level where anyone writes a query by hand: a data layer that takes the tenant from the request context and applies it, or database-level row policies that filter regardless of what the query asked for. The property you want is that the unfiltered query is not expressible, not that it is discouraged in code review.

Noisy neighbours

Isolation is not only about data. One tenant running a report across ten million rows can exhaust the connection pool, evict everyone else's cache entries, or saturate shared CPU — and the tenants who suffer did nothing wrong and can do nothing about it. This is Tier 9's rate limiting with one crucial addition: limits have to be per tenant. A global limit protects your service while cheerfully letting one customer consume everybody else's share.

Where the data is allowed to be

Some customers cannot be served from an arbitrary region, because a regulator requires their data to stay inside a border. That is not a feature request, it is a constraint on your topology, and it interacts directly with the multi-region lesson. If residency is anywhere in your future, making tenant location a first-class attribute now is dramatically cheaper than discovering later that your primary keys assumed one global namespace.

The trap

Testing with a single tenant. Every isolation bug is invisible in a suite where only tenant A exists, because the missing filter returns exactly the right rows anyway. Seed at least two tenants in your fixtures and assert that the second one's data is absent — not merely that the first one's is present. The absence assertion is the one that catches the breach.

The tradeoff sheet

Problem solved
One customer’s data, load or bug reaching another customer, in a system where they share every component.
Rejected, and why
A database per tenant is the strongest isolation and stops scaling at a few hundred tenants. A shared schema with a tenant column is simplest and one missing predicate away from a breach.
The trade
Every query, cache key, object path and queue message must carry the tenant, and the enforcement has to live somewhere that cannot be forgotten by a new engineer.
First to break at 10x
The noisy neighbour. At 10x, the usage distribution is heavy-tailed, and one tenant’s traffic sets the latency everyone else experiences.
What it does to the bill
Shared infrastructure is far cheaper per tenant and makes per-tenant cost unknowable without metering — which is how the largest customers turn out to be the least profitable.
Day-2 operations
Per-tenant metrics are the requirement, not a nicety. Without them you cannot answer which tenant caused an incident, and you cannot answer what any account costs to serve.