← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 052 · Scalability and reliability

Design a Multi-Tenant SaaS Backend

Medium 55 min

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
  1. Where does the application learn which shard holds a tenant's data, and how is that lookup kept fast?
  2. If every query must include the tenant ID, what enforces that a developer never forgets it?
  3. Should a 2-million-row import share a queue with sending password-reset emails?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • One tenant's import slows everyone downAn enterprise tenant starts importing 5 million tasks through the public API and the import job queue at the same time. The shared database shard hits 95% CPU and interactive requests for 3,000 other tenants on that shard slow to two seconds.

Run them from the workspace once your design is in place.