Case Study · Multi-tenancy · 2023 — 2024
Multi-tenant routing that resolves the tenant from the subdomain and isolates each tenant's data.
A single codebase needed to serve many tenants — each on their own subdomain — without duplicating deployments, and without any chance of one tenant seeing another's data. The risk in multi-tenancy is not routing; it's the quiet data leak when a query forgets its tenant scope.
A SaaS where each customer gets acme.app.com. Tenant resolution had to happen at the edge, before the app renders, and every data access downstream had to be scoped to the resolved tenant by construction, not by discipline.
Request path
Request
subdomain
Middleware
intercept
Parse
tenant slug
Resolve
tenant ctx
Route
rewrite
Tenant data
scoped
Failure recovery & consistency
Unknown sub
no tenant
Reject
404 / marketing
Valid
inject ctx
Scoped query
enforced
Edge
Data
Routing
Chose
·Edge-resolved tenant context
·Enforced tenant scoping in the data layer
·Single shared deployment
Gave up
·Per-tenant physical DB isolation (shared, scoped instead)
·Per-tenant custom builds
·Simplest possible routing (middleware adds a hop)
0
cross-tenant data access by construction
1
deployment serving all tenants
data
onboarding a tenant needs no code change