Video in progress
What do you do in a multi-tenant SaaS so that one big customer doesn't slow down the others?
I put per-tenant limits at every layer: API rate limits, fair scheduling in queues, query limits in the DB, and if needed, moving the big tenant onto its own resources. Before that, I make every metric visible per tenant.
📖 Answer
Just finding a "noisy neighbor" is hard: the shared dashboard only shows "p99 went up". So the first job is adding a tenant_id label to metrics, logs and slow queries. After that, in 80% of cases the culprit is found within a minute.
Isolation layers:
- Entry. A per-tenant rate limit and a concurrent-request limit, by plan. If a big customer starts an export 500 times in a day, they burn through their own quota, not anyone else's.
- Queues and background jobs. In one shared FIFO queue, if a big tenant dumps 1 million tasks, the small ones wait for hours. Use per-tenant round-robin or weighted fair queuing, or separate queues for groups of tenants.
- Database.
statement_timeout, report queries on a replica, heavy exports in a separate daily window. On shared tables, an index and partitioning bytenant_id. - Physical separation. The biggest customers are moved to their own shard or their own cell. For that, routing has to go through a "tenant → location" table from the start, not be hardcoded.
The spectrum of isolation models:
| Model | Isolation | Cost |
|---|---|---|
Everything shared (tenant_id column) |
low | cheapest |
| A separate schema per tenant | medium | migrations run N times |
| A separate DB/cell for big tenants | high | expensive, but only for a few |
In practice a hybrid is best: small tenants shared, big ones separate. It ties into the commercial side too, since you can sell the "dedicated" option as a higher plan.
Sign up to mark studied questions and save your progress.