Software Architecture / Evolution: capacity, migration, validation, and review / Lesson 21
Design multitenant isolation contracts
Define tenant context, data and capacity isolation, and end-to-end boundary tests.
On this page
Lesson goals
- Define tenant identity, trust, and data boundaries.
- Test cross-tenant denial and shared-capacity impact.
Define the tenant boundary
A multitenant system serves more than one customer or organizational tenant using some shared resources. Define the tenant identity, data ownership, trust boundary, and isolation requirements before choosing a deployment model. The correct design depends on security, regulatory, operational, and cost constraints. A separate database or process can strengthen a boundary but does not automatically prove that routing, identities, backups, and support operations are isolated.
Bind identity to tenant context
Each request must be associated with the correct tenant through an authenticated and authorized context. Do not trust a tenant identifier supplied by a client without checking that the caller is entitled to act for that tenant. The synthetic request illustrates the boundary rather than a complete authentication scheme. Propagate context deliberately across services and asynchronous work, and reject ambiguous or missing context according to the contract.
GET /reports/lab-report HTTP/1.1
Host: service.lab.example
X-Tenant-ID: lab-tenant-a
The header alone is untrusted input; it must be bound to an authenticated identity and authorized.
Enforce data and operational isolation
Data queries, caches, background jobs, exports, logs, and backups all need tenant-aware handling. A correct front-end filter does not protect a downstream query that omits the tenant boundary. Define authorization at each data access, ensure cache keys and job context cannot mix tenants, and limit support access. The example checklist lists boundaries to review; actual controls must match the chosen storage and deployment model.
review: request authorization
review: data query and cache key
review: background job, export, backup, restore
The checklist identifies review points; it does not prove isolation controls are implemented.
Account for shared capacity
Isolation also includes availability and performance: one tenant’s burst can consume shared queues, connections, or compute and delay others. Define quotas or fairness policies and their rejection behavior according to business requirements. Measure user outcomes per tenant without placing sensitive or unbounded identifiers in telemetry. Test a bounded noisy-neighbor scenario in a disposable environment and verify recovery after the load stops.
Test isolation end to end
Use synthetic tenants and identities to test an allowed operation within one tenant and a denied cross-tenant operation through every relevant boundary. Include background processing, cache reuse, exports, and restore procedures where applicable. Verify both data correctness and availability under the agreed workload. Record the assumptions, test coverage, and residual risks; one passing API test does not certify every administrative or recovery path.
Common errors and fixes
Trusting a client-supplied tenant ID alone
- Why it happens
- Context was not bound to identity and authorization.
- How to fix it
- Verify the caller’s entitlement to the tenant at each boundary.
- Prevent it next time
- Test denied cross-tenant requests.
Isolating the interface but forgetting background work
- Why it happens
- Tenant context did not reach the job or query.
- How to fix it
- Add context and authorization under the contract and address affected data.
- Prevent it next time
- Test every path including export and restore.
Ignoring a neighbor’s resource consumption
- Why it happens
- No clear capacity or fairness policy exists.
- How to fix it
- Test suitable limits under representative load.
- Prevent it next time
- Monitor tenant outcomes and define rejection behavior.
2 practice exercises
1. A user changes the tenant ID in a request. Is valid syntax enough to accept it?
Show worked solution
No. Verify identity and tenant authorization on the server and at each data access boundary.
2. An API test passes but a background export mixes data. What follows?
Show worked solution
The test did not cover export. Correct tenant-context propagation and authorization, then test the path and affected data.
Key takeaways
- Bind tenant context to identity and authorization at every boundary.
- Test data, capacity, background paths, and recovery.