What a tenant is
A tenant is a customer organisation that uses your product with its own users, data and settings: a school using an LMS, a restaurant chain using a POS, a company using a ticketing tool. Multi-tenancy means many tenants share one deployment of your software rather than each getting a separate copy.
Why share? Cost and speed. One deployment is cheaper to run, every tenant gets new features at once, and you operate one system instead of five thousand.
The price: isolation becomes your responsibility. A bug, a missing filter or one tenant's traffic spike can now affect everyone.
An apartment building is multi-tenant. Residents share the foundation, lifts and water mains (cheap), but each flat has its own lock (data isolation), its own electricity meter (cost attribution), and a building rule that one flat's party can't cut the water pressure for everyone else (noisy-neighbour control). A villa per family is the single-tenant alternative: perfect isolation, very expensive.
Tenancy models
| Pool | Bridge | Silo | |
|---|---|---|---|
| Cost per tenant | Lowest | Medium | Highest |
| Isolation | Logical (code must enforce it) | Partial | Physical |
| Noisy-neighbour risk | Highest | Medium | Lowest |
| Onboarding | Instant (insert a row) | Fast (create a schema) | Slower (provision resources) |
| Ops at 10,000 tenants | One system to run | Many schemas to migrate | 10,000 stacks to upgrade |
| Fits | Freemium, SMBs | Mid-market | Enterprise, regulated, data residency |
A common winning pattern: pool by default, silo for the top tier. Small customers share; a large bank pays for a dedicated database in its required region, deployed by the same code and pipeline.
Isolating data
In the pool model, every row carries tenant_id, and every query must filter by it. One forgotten WHERE tenant_id = ? leaks data across customers, the worst bug a SaaS company can ship. Use defence in depth:
- Tenant context from the token: the tenant ID comes from the authenticated token, never from a URL parameter the user can edit.
- A data-access layer that requires it: repository methods that take a tenant context and add the filter automatically; raw queries flagged in review.
- Database row-level security (Postgres RLS): the database itself refuses rows from other tenants, even if the app forgets.
- Per-tenant encryption keys for sensitive data: a leaked row is unreadable without that tenant's key, and deleting the key "crypto-shreds" the tenant's data.
- Tests that try to cross tenants: automated tests that log in as tenant A and request tenant B's resources.
Caches, search indexes, queues and object storage need the same care: prefix cache keys with the tenant (t42:product:9), filter search by tenant, and keep tenant files under per-tenant prefixes with matching access policies.
Noisy neighbours
One tenant runs a giant export, imports 5 million records, or gets featured on TV. In a shared system, everyone else slows down. Defences:
| Layer | Control |
|---|---|
| API | Per-tenant rate limits and quotas by plan (Rate Limiting Algorithms and Overload Protection) |
| Workers | Per-tenant concurrency caps; fair queuing so one tenant's 1M jobs don't delay another's 10 |
| Database | Per-tenant statement timeouts and connection limits; move heavy tenants to their own shard |
| Storage | Quotas on records, files and bandwidth |
| Placement | Spread big tenants across shards; isolate whales in dedicated cells |