
A multi-tenant product stores many customers in one operational system. The architecture has to make it difficult to read or change another customer’s data, and it has to stay understandable when the team ships a weekly release.
Choose a tenancy model you can explain
Three patterns cover most products. A shared database with a tenant column is simple and cheap, and it demands discipline in every query. A schema per tenant adds isolation with more migration work. A database per tenant is the strongest boundary and the most operational overhead. Pick the pattern from the data sensitivity and the number of tenants you expect, then write it down.
Make tenant context explicit
The request should resolve the tenant before business logic runs, from the host name, a path, or a token claim. Data access then receives that tenant as a required argument. Hiding it in a global variable makes it easy to forget in a background job.
- Resolve tenant before handlers run.
- Pass tenant identity into every query and file path.
- Partition object storage and search indexes the same way.
- Test a cross-tenant read as a failing test, not as a manual check.
Plan migrations and noisy neighbors
A shared schema means one migration affects every customer. Rehearse it. Large tenants can dominate CPU, queues, and storage. Limits on background work and a way to see usage per tenant belong in the first version if you sell to mixed sizes.
| Concern | What to decide early |
|---|---|
| Data isolation | Shared row, schema, or database |
| Files and search | Prefix or index per tenant |
| Release | How a migration is rehearsed |
| Abuse and size | Limits and visibility per tenant |