Skip to main content
PreparationZone Logo
PrepZone

Multi-Tenant SaaS

Shared infrastructure with tenant isolation — schema-per-tenant, row-level security and noisy-neighbour control.

Pass checkpoint below

Read these first

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_id column 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

CLIENT
Tenant A / B …
SECURITY
Cognitotenant in JWT
NETWORK
API Gateway
COMPUTE
Shared EKSsame fleet
DATABASE
RDS pooledtenant_id RLS
DATABASE
RDS siloschema per tena…
Cognito JWT tenant claim → shared EKS with row-level or siloed RDS.

Tenancy model comparison

AspectModelTrade-off
Shared schema + RLSLowest cost, simplest opsRisk of query bugs leaking data
Schema per tenantGood isolation, single DB clusterSchema migration × N tenants
DB per tenantStrongest isolation, custom SLAsExpensive; 1000 tenants = 1000 DBs
HybridSmall tenants shared; enterprise dedicatedTwo code paths to maintain
  • Shared schema + RLS

    ModelLowest cost, simplest ops
    Trade-offRisk of query bugs leaking data
  • Schema per tenant

    ModelGood isolation, single DB cluster
    Trade-offSchema migration × N tenants
  • DB per tenant

    ModelStrongest isolation, custom SLAs
    Trade-offExpensive; 1000 tenants = 1000 DBs
  • Hybrid

    ModelSmall tenants shared; enterprise dedicated
    Trade-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

Java
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:

Java
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.