Architecture / 8 / 9
Multi-tenancy
A B2B invoicing service keeps 1 200 customer companies in one database. One forgotten `WHERE tenant_id` leaks invoices, one big customer's export slows everyone, and one migration can break them all at once. The fixes: isolation enforced by the database, a tenant taken only from the token, per-tenant quotas, a silo for the big tenant behind a routing catalog, per-tenant keys and migrations in waves.
- 14 min
- Advanced
- 11 steps
- Rows leaked
- 0
- API p99
- 120 ms
- Hit by one change
- 100 %
- request
- reply
- redelivery
- duplicate
- lost
Numbers are a model scenario, not measurements
The real request
Invoicing API → Shared DBRequest
SELECT id, total FROM invoices
WHERE tenant_id = 't_17'1
AND status = 'open';
-- 1 200 tenants, one schema, one table2
Response
3 rows3
tenant_id— Which company owns the row. Every query must filter by it.one table— Invoices of all tenants sit side by side in the same table.3 rows— Correct: t_17 sees only its own three open invoices.
Build it yourselfCheat sheetCompare lessons
Course: 74 lessons
01 Foundations
02 Scaling
03 Data & storage
04 Communication
05 Reliability
06 Architecture
07 Security
08 Shipping
09 Whole systems
10 Business processes
11 Case studies