SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
  • Client-Server
  • Monolithic Architecture
  • Microservices
  • Serverless
  • Event-Driven Architecture
  • Peer-to-Peer (P2P)
  • Hexagonal Architecture
  • CQRS
  • Event Sourcing
  • Domain-Driven Design (DDD)
  • Layered (N-Tier) Architecture
  • Containers and Docker
  • Kubernetes Basics
  • Clean Architecture and Modular Monolith
  • Multi-Tenancy
  • Cloud Basics: Regions, Zones and Edge
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Architecture/Architectural Patterns

Multi-Tenancy

Serve many customers from one system while keeping their data apart, and their noisy neighbours in check.

⏱ 13 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Multi-tenancy means one system serves many customers (called tenants), while keeping each customer's data and experience separate.

  • Almost every SaaS product works this way: thousands of companies use the same software, and none of them can see the others' data.
  • You choose how much to share: one table for everyone (cheap, risky), a schema or database per tenant (safer, costlier), or a whole separate stack per tenant (strongest, most expensive).
  • Two big problems to solve: data leaks between tenants and noisy neighbours (one busy tenant slowing everyone else).

02Concept: What is it?

A tenant is one customer organisation, such as a company that signed up for your app. Running a separate copy of your software for each one is safe, but it is costly: ten thousand customers would mean ten thousand deployments to update. Multi-tenancy shares the running system between tenants to cut cost and effort, and then adds walls so tenants cannot see or harm each other.

The main design question is where the walls go. There is a ladder from cheap and thin walls to costly and thick walls.

The isolation ladder
🧺Shared tablestenant_id column
↓more isolation, more cost
🗂️Schema per tenantone server
↓
🗄️Database per tenantown database
↓
🏰Stack per tenanta silo
Moving down the ladder adds isolation and cost. Many products mix levels (a hybrid).
🧠The tenant id is the key to everything
In a shared system, every request must carry who the tenant is, and every query, cache key, file path and log line must respect it. Forgetting it once is how data leaks happen.

03Real-Life Example

🍵An Apartment Building
An apartment building shares one roof, one lift and one set of pipes between many families (tenants). That is far cheaper than building a house for each family. But each family has a locked front door. A noisy party in one flat can still annoy the others through the walls, so the building has rules and thick walls. A very rich or private tenant may pay for a whole floor, or a separate house on the same street.
Apartment building
Multi-tenant system
A family renting a flat
A tenant (a customer company)
The shared roof and pipes
Shared servers and code
A locked front door
Data isolation: the tenant_id filter or a separate database
A loud party next door
The noisy neighbour problem
House rules about noise
Per-tenant rate limits and quotas
A whole floor for one tenant
A separate database or stack for a big customer
Moving out and clearing the flat
Deleting a tenant's data
One request, and where the tenant is checked
👤User of Acme
→↓login
🪪Tenant: acmefrom the login
→↓on every call
🧠App codeadds the tenant
→↓filtered
🗄️Acme data only

04Why Do We Need It?

💸Lower cost
Many customers share servers, so each one costs much less to serve.
🚀One version to update
Fix a bug or ship a feature once, and every tenant has it.
📈Easier onboarding
A new customer is a few rows (or one new schema), not a new data centre.
📊Better use of hardware
Quiet tenants and busy tenants even each other out.
🔐Still safe
With the right walls, customers get strong privacy even on shared hardware.
⚙️Choice by customer
Small customers share. Big or regulated ones can get their own database.
Share what you safely can to save money, and wall off what you must to protect each customer.

05Where Do We Use It?

☁️SaaS products
CRM, project tools, accounting, chat for companies: nearly all are multi-tenant.
🏗️Cloud platforms
Cloud providers share hardware between customers and isolate them with accounts and virtual networks.
🏢Internal platforms
A company platform serves many teams as tenants, with quotas for each.
🛍️Marketplaces
Many sellers (tenants) with their own shops on one shared platform.
🏥Regulated industries
Health or finance customers may require their own database or region.
🎓Education software
Each school or university is a tenant with its own users and records.

06Types / Parts / How It Works

The main tenancy models

ModelHow data is kept apartGood forWatch out for
Shared tablesOne set of tables, a tenant_id column on every rowMany small tenants, lowest costEvery query must filter on tenant_id. One missed filter leaks data. Noisy neighbours.
Schema per tenantOne database server, a separate schema (set of tables) for each tenantMedium number of tenants, some customisationThousands of schemas are hard to migrate and manage.
Database per tenantEach tenant has its own databaseStrong isolation, per-tenant backup and restoreMany databases to upgrade, monitor and pay for.
Stack per tenant (silo)A separate copy of the app and data for each tenantLarge or regulated customersHighest cost and most operational work.
Hybrid (bridge)Small tenants pooled, large or special ones siloedMost real SaaS products over timeTwo code paths and two sets of tooling.
Shared tables versus a database per tenant
Shared tables
🗃️invoicesrows: acme, globex, initech
🔎WHERE tenant_id = ?must never be forgotten
Database per tenant
🗄️acme db
🗄️globex db
🗄️initech db
Cheaper, thinner wall Costlier, thicker wall

Other things that must be tenant-aware

Part of the systemWhat to do
Cache keysInclude the tenant id in every key, or one tenant may read another's cached data.
Rate limits and quotasLimit per tenant, so one customer cannot use everything.
ShardingUse the tenant id (or a hash of it) as part of the shard key, and plan for one huge tenant.
Files and queuesPrefix object paths and queue names with the tenant.
Logs and metricsTag them with the tenant, but never log another tenant's private data.
PermissionsRoles are checked inside the tenant. See RBAC.
VisualizerPick a tenancy model and add a noisy neighbourSwitch between the four models, raise one tenant's load, and watch other tenants' latency and the cost. Then forget the tenant_id filter on the shared tables and run the query.
How are tenants kept apart?

Shared tables (tenant_id column). All tenants share the same tables and the same servers. Cheapest. Every query must filter on tenant_id.

Shared capacity is 40 load units (illustrative). Each quiet tenant uses 1. Bar = how full the shared resource is.
73% full. Isolation level: ●○○○
Other tenants' latency
50 ms
normal is 50 ms (illustrative)
Cost per tenant
1
illustrative units
Total cost
20
for 20 tenants
A bad bug hits
All tenants
blast radius
Shared tables (tenant_id column): All tenants share the same tables and the same servers. Cheapest. Every query must filter on tenant_id.
Teaching toy: the shared "invoices" table in the pooled model. You are logged in as tenant acme.
SELECT * FROM invoices WHERE tenant_id = 'acme'

A teaching sketch. The capacity, the cost units, the 50 ms base latency and the "how much noise others feel" factors are made-up, illustrative numbers. Real results depend on your database, your limits and your hardware. Row-level security and per-tenant rate limits can protect even the pooled model.

07How to Use It / Steps / Implementation

Designing it carefully

  1. 1
    Decide the isolation level
    Start from your customers: how sensitive is the data, what do contracts require, how many tenants will there be, and how big can one get?
  2. 2
    Resolve the tenant once, early
    Work out the tenant from the login (a claim in the token or session) at the edge, then pass it along. Never trust a tenant id sent freely by the client.
  3. 3
    Enforce it in one place
    Use a data-access layer that always adds the tenant filter. Where your database supports it, add row-level security as a second lock.
  4. 4
    Put the tenant in every key
    Cache keys, file paths, queue names and search indexes should all include it.
  5. 5
    Limit each tenant
    Apply rate limits and quotas per tenant, and keep heavy jobs from monopolising shared workers.
  6. 6
    Plan the lifecycle
    Onboarding should be automatic. Offboarding must delete the tenant's data, including backups and caches, within your policy.
  7. 7
    Test for leaks
    Write tests that log in as one tenant and try to read another's data through every API. Run them on every release.
⚠️Cross-tenant leaks are the worst bug
A missing filter shows one customer another customer's private data. It can end a business. Use more than one defence: a central filter, row-level security, tests and code review.
💡Hybrid is normal
Start pooled for small tenants. When a big or regulated customer arrives, give that tenant its own database. Design the code so the data layer can point a tenant at a different place.

08Key Terms to Know

TermMeaning in easy words
TenantOne customer organisation using the shared system
Multi-tenancyServing many tenants from one running system, with their data kept apart
Tenant idThe identifier that says which tenant a request or row belongs to
Pooled modelTenants share the same tables, separated by a tenant id
Silo modelEach tenant gets its own full copy of the stack
Noisy neighbourA heavy tenant that slows down others who share the same resources
Row-level securityA database feature that automatically limits which rows a user can see
QuotaA cap on what a tenant may use (requests, storage, seats)
Data residencyA rule that a tenant's data must stay in a certain country or region
Blast radiusHow many tenants are hurt when something goes wrong
OffboardingRemoving a tenant and deleting their data safely

09Pros, Cons and Trade-offs

✅ Pros
  • Much lower cost per customer
  • One code base and one release to maintain
  • Fast onboarding of new tenants
  • Can mix levels: pool the small, silo the large
  • Efficient use of hardware
⚠️ Cons
  • A missing filter can leak data between tenants
  • Noisy neighbours can hurt everyone
  • Harder per-tenant backup, restore and customisation (in shared models)
  • Compliance rules may require stronger isolation
  • One bad release or outage affects many tenants

Trade-offs

ChoiceWe gainWe lose
Shared tablesLowest cost, simplest operationsThinnest isolation, noisy neighbours, leak risk
Schema or database per tenantStronger walls, per-tenant restoreMore objects to manage and migrate
Silo per tenantBest isolation and customisationHighest cost, many deployments
Per-tenant limitsFair sharing, protection from abuseExtra work, and some tenants hit limits
Tenant id from the tokenHard for a client to fakeEvery service must read and respect it
Hybrid modelRight level for each customerTwo ways to run and to test

10Common Problems and Mistakes

Common mistakes

  1. A forgotten tenant filter. One query without it shows other customers' data. Centralise the filter and test for it.
  2. Trusting a tenant id from the client. A user can change it. Take it from the verified login.
  3. Cache keys without a tenant. The cache serves tenant A's page to tenant B.
  4. No per-tenant limits. One tenant's heavy report or import slows everyone.
  5. Thousands of schemas. Migrations that take hours because each schema must be changed one by one.
  6. One huge tenant on one shard. It creates a hot shard. Plan to move or split big tenants.
  7. Ignoring deletion. Data of a left tenant stays in backups, search indexes and caches.

Things to watch

🔊Noisy neighbours
Watch latency and usage per tenant. Add limits, queues per tenant or move the big one out.
🛂Leaks
Run automatic tests that try to cross tenants. Review every raw query.
📜Compliance
Some customers need data in a given region, or their own keys for encryption.
🔧Migrations
Schema changes must work for every tenant, and can be rolled out in waves.

11Real-World Examples

☁️Business SaaS
Most business SaaS products serve many companies from one system, often with a hybrid model for the largest customers.
🏗️Cloud providers
Customers share hardware, and are isolated by accounts, virtual networks and permissions.
🛍️Marketplace platforms
Many shops run on one platform, each as a tenant with its own data and settings.
🗝️Own keys
Some SaaS products let enterprise tenants bring their own encryption keys.
🧯Row-level security
Databases such as PostgreSQL offer row-level security policies that add a second line of defence.
🌍Regional deployments
Tenants are placed in a region that matches their data residency needs.
📝Note
Features and names differ by product. Check your database and platform documentation before you rely on a specific feature.
Mini case: a big customer outgrows the pool
🧺Pooled tables500 small tenants
→↓one tenant grows
📈Big tenantslows the rest
→↓move out
🗄️Own databasesame app code
The hybrid approach moves one tenant without touching the others.

12Related Topics to Read Next

Rate Limiting→

Per-tenant limits keep a noisy tenant from hurting the others.

Sharding→

Tenants are a natural way to split data across machines.

Shard Keys, Hot Shards and Resharding→

One huge tenant can make a hot shard.

RBAC→

Roles are checked inside each tenant.

Bulkhead→

Separate resource pools stop one tenant sinking the ship.

Relational Databases→

Schemas, row-level security and per-tenant databases live here.

Encryption at Rest→

Per-tenant keys give stronger separation of stored data.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: many customers (tenants) on one system, with data kept apart.
  • ✔Ladder: shared tables, schema per tenant, database per tenant, stack per tenant.
  • ✔Rule: every query, cache key and file path respects the tenant id.
  • ✔Tenant id: take it from the verified login, never from a client field.
  • ✔Worst bug: a missing filter leaks one tenant's data to another.
  • ✔Noisy neighbour: fix with per-tenant limits, separate pools or a dedicated stack.
  • ✔Hybrid: pool the small tenants, silo the big or regulated ones.
  • ✔One line: “Share to save money, and add walls to keep each customer safe.”
← Previous
Clean Architecture and Modular Monolith
Next →
Cloud Basics: Regions, Zones and Edge