When you host one website, architecture barely matters. When you host thousands — free sites, paid sites, custom domains — every decision gets multiplied. These are the patterns that have held up for me.
Request flow
Every request starts with one question: which tenant is this?
Resolving the tenant at the edge means the origin almost never sees traffic for a page that hasn't changed.
Three rules for tenant isolation
- Tenant ID on everything. Every row, every storage key, every cache key. No exceptions, no "global" shortcuts.
- Separate free from paid. Different hostnames for freemium and custom-domain sites lets you apply different limits, caching and abuse rules without branching code.
- Immutable versions. A publish writes a new version; the domain just points at it. Rollback becomes a pointer change.
Publishing as a pointer swap
Because versions never mutate, the cache can be aggressive. Invalidating one tenant's site is a single purge by tag.
What I'd tell my past self
- Put the domain map in a fast key-value store from day one.
- Treat custom-domain SSL as a queue, not a request.
- Measure per-tenant cost early — a few heavy sites will surprise you.
Multi-tenancy isn't one big decision. It's a hundred small ones that all say: this belongs to exactly one customer.