Medium · 12 steps · ~60 min
Design a multi-tenant SaaS platform
Share one platform between hundreds of customers without letting any of them hurt the others.
A software company serves hundreds of customers (tenants) from one platform. Sharing is what keeps it affordable, but one tenant's traffic spike or data-hungry job must not slow everyone else, and no tenant may ever see another's data.
Same problem as SalesforceShopifySlack
How it works
- Every request is tied to a tenant from the caller's credentials.
- Capacity is shared, but each tenant has a limit and a placement.
- Premium tenants may get stronger isolation for a higher price.
What you'll build
- A tenant-aware API and data model
- A gateway and cache for the shared path
- A rate limiter that stops a noisy neighbour
- Sharding by tenant and isolation tiers
- Cheap background compute, and surviving a cold cache and a lost primary
Steps
- 1Design the API
- 2Design the data model
- 3Serve 1,500 requests per second
- 4Add a gateway and cache at 10,000 requests per second
- 5Stop a noisy neighbour at 90,000 requests per second
- 6Global limit or per-tenant limit?
- 7Shard by tenant at 40,000 requests per second
- 8Isolation tiers
- 9Run tenant background jobs cheaply
- 10Survive a cold cache at 12,000 requests per second
- 11Lose the primary database
- 12Deep dive: preventing cross-tenant leaks