1Understand
The idea
Multi-tenancy means one platform serves many customers while each believes they are alone: no cross-tenant data leaks, predictable performance, and unit economics that do not provision a dedicated database per free signup. Models span pooled rows with tenant_id, schema-per-tenant bridge, and silo databases for enterprise/regulatory wins.
The interview checks discipline: tenant_id on every SQL query, cache key, queue message, and search filter, not “we trust developers to remember.” Noisy neighbor controls (per-tenant rate limits, fair queues) matter as much as schema diagrams.
Silo everything on day one is ops bankruptcy; pool without tenant keys is a breach waiting for a cache typo. Enterprise exceptions should be data-driven (contract, residency, noisy workload), not habit.
Intuition
Pooled (shared tables). Cheapest; tenant_id column + composite indexes (tenant_id, created_at). Middleware sets TenantContext from JWT claim or subdomain. Postgres RLS optional safety net: policy tenant_id = current_setting('app.tenant'). Leak = missing WHERE clause or wrong cache key.
Bridge (schema per tenant). Same cluster, tenant_acme.products, stronger isolation, migration runs N times; connection pool per schema or search_path switch.
Silo (DB per tenant). Fortune-500 contract, data residency Germany-only, custom schema, registry maps tenant → connection string; backup/restore per customer; cost scales with enterprise count, not MAU.
Tenant resolution. acme.app.com → tenant_id=acme; API key metadata includes tenant; never accept raw tenant_id from client without binding to credential.
Fairness. Gateway rate limit per tenant tier; worker pool concurrency caps; noisy batch export → dedicated queue with max parallel jobs per tenant.
Cross-cutting: search index shared with mandatory tenant_id filter; S3 prefix s3://bucket/{tenantId}/...; logs include tenant (hashed in shared SIEM). Support break-glass impersonation with audit trail.
Onboarding: create tenant row + defaults, not new RDS instance per trial.
Metering & billing. Per-tenant usage counters (API calls, storage bytes) enable invoices and prove fairness when enforcing quotas.
Deletion / offboarding. Tenant export and hard delete across SQL, search, S3 prefix, orchestrated workflow; tombstone tenant_id everywhere.
Upgrade path. Start pooled; promote tenant to silo when contract signed, registry flip without code fork if connection routing abstracted early.
What you will be able to do
- Choose pooled vs siloed tenancy with a reason
- Prevent cross-tenant data access in keys and queries
- Limit noisy neighbors with quotas
When this comes up
- Tenant id
- Noisy neighbor
- Silo vs pool
- Row-level security
2See it
Architecture sketch
Pooled tenancy with isolation controls
Default shared compute/DB with tenant_id. Silo when contract or noisy neighbor demands.
Walkthrough
Every query carries tenant
Missing filter is a data leak
1 / 4
Resolve tenant from host or token. Never trust a client-supplied tenant id alone.
Read the walkthrough as text
Worked example, B2B analytics SaaS: 40k SMB tenants + 2 regulated enterprises on silo.
Workload: dashboards, API exports, shared Postgres, Redis cache, ES search.
- Default pool: all SMB on one Postgres; every table has
tenant_id; index(tenant_id, id)on hot tables. - Request path: auth resolves tenant from subdomain; middleware
SET LOCAL app.tenant_id; repository base class appends tenant predicate. - Cache: keys
t:{tenantId}:dashboard:summary, neverdashboard:summary. - Search: ES query always
filter: { term: { tenant_id } }from server context, not client param. - Fairness: free tier 100 rps, pro 2k rps at API gateway; export jobs max 2 concurrent per tenant.
- Enterprise silo: tenant registry flag
dedicated_db=true→ route tobigco-db.internal; same codebase, different datasource bean. - Testing: integration test attempts cross-tenant read with two JWTs, must 403/empty.
- Noisy neighbor: one tenant 10TB export, shard to low-priority queue, does not block interactive queries (separate pool).
What interviewers listen for: tenant in every layer; pool vs silo tradeoff; quotas; leak prevention example; enterprise exception justified.
Napkin math
default = shared pool + tenant_id on every row
queries always scoped (middleware / RLS)
quotas: QPS and storage per tenant
noisy neighbor → rate limit or silo DB
enterprise: dedicated schema / cluster
Isolation is a product of filters, quotas, and sometimes silos.
3Answer it
How to answer in an interview
When SaaS, B2B, “many customers on one stack”:
- Isolation model, pool default; silo when and why.
- Tenant context, how resolved and enforced.
- Data plane, SQL, cache, search, object keys.
- Fairness, rate limits, queue fairness, tiers.
- Blast radius, one bad tenant cannot exhaust fleet.
- Enterprise path, registry routing without forked codebases.
- Testing / RLS, negative cross-tenant cases.
Phrases: “pooled by default,” “tenant-scoped cache keys,” “per-tenant concurrency caps,” “silo for residency not for hobby tier.”
- Support access, break-glass impersonation with audit trail, not shared admin password.
- Close, “Isolation is a property of every query, not a deployment diagram ornament.”
Answer checklist
Tradeoffs & numbers
- Pooled: lowest $/tenant; requires ruthless code review and RLS optional backstop.
- Schema-per-tenant: middle isolation; migration N-way scripts hurt.
- DB-per-tenant: strongest; connection limits, backup cost, schema drift across customers.
- Per-tenant limits: fairness; billing complexity mapping tier → quota.
- Shared ES cluster: cost-efficient; one missing filter catastrophic, automated query lint.
- When NOT silo: free tier, <100 tenants, no regulatory clause, pool until contract forces.
- Custom schema tenants: even in pool model, feature flags per tenant, avoid 40 forked code paths.
- Interview tip: give a leak scenario (
cache keymissing tenant) and the fix in the same breath.
Kinds of questions (4)
Same pattern, different interview surfaces. Recognise which variant you are in before you answer.
Pooled shared DB
Example. 10k law firms on one Postgres; each must see only their matters. `tenant_id` on every query/cache key; noisy-neighbor limits; when silo vs pool is a contract-driven exception.
How. tenant_id on matters table; composite indexes; middleware injects tenant; integration tests for IDOR across firms. Middleware injects tenant; integration test that cross-tenant read fails; fair queue per tenant.
Schema- or DB-per-tenant
Example. Hospital chain mandates isolated schema for HIPAA audit scope. `tenant_id` on every query/cache key; noisy-neighbor limits; when silo vs pool is a contract-driven exception.
How. Tenant registry selects schema; migrations scripted per schema; backup per tenant for restore SLA. Middleware injects tenant; integration test that cross-tenant read fails; fair queue per tenant.
Per-tenant rate limits
Example. One tenant’s buggy integration loops `GET /events` at 5k rps. `tenant_id` on every query/cache key; noisy-neighbor limits; when silo vs pool is a contract-driven exception.
How. Gateway token bucket per API key; 429 with Retry-After; internal alert on sustained throttle for capacity planning. Middleware injects tenant; integration test that cross-tenant read fails; fair queue per tenant.
Enterprise silo
Example. Bank contract requires dedicated RDS in `eu-central-1` only for their data. `tenant_id` on every query/cache key; noisy-neighbor limits; when silo vs pool is a contract-driven exception.
How. Routing datasource from registry; shared app binary; separate backup/DR runbook, not default onboarding path. Middleware injects tenant; integration test that cross-tenant read fails; fair queue per tenant.
Common mistakes
Failure modes the AI coach watches for when you practise open questions.
Forgotten tenant filter
Avoid. SELECT * FROM orders WHERE id=?. Any tenant can read another’s row.
Prefer. Always constrain by tenant_id (or DB RLS). Test cross-tenant access.
Weak sketch
Bad
Stronger sketch
Good
Missing tenant key
Why it happens. Shared caches and connection pools reuse entries across tenants; one wrong key exposes another customer’s payload.
How it fails. Redis caches `report:weekly` globally; Tenant B sees Tenant A’s revenue chart.
Fix. Prefix `tenantId` on every cache, queue, and object key; code review checklist; optional RLS.
No per-tenant quotas
Why it happens. A single heavy tenant can exhaust DB connections, API capacity, or worker threads for all others.
How it fails. Global rate limit 10k rps shared; one enterprise runs batch export and starves SMB UI.
Fix. Per-tenant gateway limits, fair queue scheduling, tiered concurrency caps on background jobs.
Silo everything too early
Why it happens. Provisioning isolated databases per signup multiplies cost, migration time, and on-call surface without compliance benefit.
How it fails. Every free trial triggers Terraform for dedicated RDS + ES cluster.
Fix. Pooled multi-tenant default; silo triggered by contract, residency, or measured noisy-neighbor failure.
4Practise
Concept check
A short quiz on this lesson before open questions. Optional, and it does not gate practice.
Open questions
- about 8 min
Pooled multi-tenant DB
You host 20k SMB customers on one Postgres cluster. How do you prevent cross-tenant data leaks in SQL, caches, and background jobs?
- about 8 min
When to silo
Compare pooled rows with tenant_id vs dedicated database per customer. For a early-stage B2B SaaS with two enterprise prospects asking for isolated infrastructure, what default would you ship and when would you silo?
- about 8 min
Per-tenant fairness
One integration partner runs a nightly job that calls your shared API at 5k rps and degrades smaller tenants. What quotas and limits do you add at the gateway and inside the platform?
- about 8 min
Enterprise silo routing
Fortune-500 customer “BigCo” pays for a dedicated database in their AWS account while smaller tenants stay pooled. How does the same application code route queries and caches for both modes?
Ready to practise?
Write an answer, get AI coaching, then revise. You are not building a real system.