Why this matters
- StreamHub for Business lets companies white-label the platform for their employees — each company is a tenant sharing the same deployment.
- Poor isolation causes data leaks (tenant A sees tenant B's data) or noisy-neighbour problems (one tenant's load degrades everyone).
- The tenancy model you choose at launch is expensive to change later — design for the target customer segment upfront.
Multi-tenancy isolation models
- Shared database, shared schema —
tenant_idcolumn on every table; row-level security enforces boundaries. - Shared database, schema per tenant — separate PostgreSQL schema per tenant; stronger isolation, moderate overhead.
- Database per tenant — dedicated DB instance; maximum isolation, highest cost and ops burden.
- Compute isolation — shared app tier with tenant context, or dedicated pods per large tenant.
- Noisy-neighbour control — per-tenant rate limits, resource quotas, and fair scheduling.
Multi-tenant SaaS architecture
Tenancy model comparison
| Aspect | Model | Trade-off |
|---|---|---|
| Shared schema + RLS | Lowest cost, simplest ops | Risk of query bugs leaking data |
| Schema per tenant | Good isolation, single DB cluster | Schema migration × N tenants |
| DB per tenant | Strongest isolation, custom SLAs | Expensive; 1000 tenants = 1000 DBs |
| Hybrid | Small tenants shared; enterprise dedicated | Two code paths to maintain |
Shared schema + RLS
ModelLowest cost, simplest opsTrade-offRisk of query bugs leaking dataSchema per tenant
ModelGood isolation, single DB clusterTrade-offSchema migration × N tenantsDB per tenant
ModelStrongest isolation, custom SLAsTrade-offExpensive; 1000 tenants = 1000 DBsHybrid
ModelSmall tenants shared; enterprise dedicatedTrade-offTwo code paths to maintain
StreamHub uses shared schema with row-level security for SMB tenants and dedicated cells for enterprise.
Shared schema with row-level security
CREATE TABLE streams (
id UUID PRIMARY KEY,
tenant_id UUID NOT NULL,
title VARCHAR(255),
creator_id UUID,
created_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX idx_streams_tenant ON streams(tenant_id);
ALTER TABLE streams ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON streams
USING (tenant_id = current_setting('app.tenant_id')::UUID);
Every request sets the tenant context before querying:
def get_streams(tenant_id: str) -> list:
with db.connection() as conn:
conn.execute("SET app.tenant_id = %s", [tenant_id])
return conn.execute("SELECT * FROM streams ORDER BY created_at DESC")
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 4 sections
- Tenant context propagation
- Noisy-neighbour mitigation
- Tenant onboarding and provisioning
- Scale estimates
Test yourself
Answer these before moving on — recall is what makes it stick.