A project-management SaaS serves 20,000 business tenants, from five-person agencies to enterprises with 50,000 users. All tenants share the same application, which handles 40,000 requests per second at peak. The largest 1% of tenants generate almost half of all traffic, and one tenant's nightly bulk import has previously slowed the product for everyone. Enterprise customers demand that their data is never visible to anyone else, some require their data to stay in the EU, and a few pay for dedicated capacity. The team must keep costs low for small tenants while giving large ones predictable performance.
Functional requirements
Route every request to the right tenant's data with the tenant identified from the login token
Apply per-tenant rate limits and quotas based on their plan
Partition tenant data so large tenants can be moved to their own shard or database
Keep EU tenants' data in EU infrastructure
Run tenant-heavy background jobs (imports, exports, reports) without hurting interactive traffic
Non-functional requirements
No request ever reads or writes another tenant's data
Interactive requests stay under 250 ms at p95 even when one tenant spikes
Moving a tenant between shards causes no data loss and at most seconds of read-only time
Cost per small tenant stays low through shared resources
Constraints and scale
20,000 tenants; the top 200 produce about 45% of traffic
40,000 requests per second at peak
4 TB of tenant data, with the largest tenant holding 300 GB
You will practise
Compare pooled, sharded and dedicated tenant isolation models
Protect shared capacity with per-tenant rate limits and separate job queues
Map tenants to shards through a routing directory that supports rebalancing
Show 3 hints
Where does the application learn which shard holds a tenant's data, and how is that lookup kept fast?
If every query must include the tenant ID, what enforces that a developer never forgets it?
Should a 2-million-row import share a queue with sending password-reset emails?