What Is Multi-Tenancy and Is It Right for You?
A tenant is an organization or academy using your platform. Multi-tenancy means: one codebase + shared infrastructure + genuine isolation between customers.
- Right for you if: you're selling the same platform to multiple clients without separate deployments per client
- Wrong fit if: each client needs deep code-level customizations that differ per tenant
- The benefit: $500/month operating cost instead of $500/client/month
- The core challenge: data isolation — one mistake means a client sees another's data
Three Data Isolation Strategies
There's no single best solution — the right choice depends on your scale, budget, and security requirements.
| Strategy | Isolation Level | Complexity | Cost | Best For |
|---|---|---|---|---|
| Shared Schema | tenant_id column | Low | Low | Startups, < 100 tenants |
| Schema per Tenant | PostgreSQL Schema | Medium | Medium | 50-500 tenants |
| DB per Tenant | Separate database | High | High | Enterprise, healthcare, legal |
Shared Schema: Fastest and Cheapest to Start
Every database table includes a tenant_id column. Every query filters by this identifier automatically. The simplicity is a feature — but it requires strict discipline.
- Every table: id, tenant_id, created_at — tenant_id is NEVER NULL
- Row Level Security in PostgreSQL: enforces isolation at the database level
- Composite index required: (tenant_id, id) not just id alone
- Risk: forgetting WHERE tenant_id = ? in one query = major security breach
- Drizzle ORM or Prisma can be configured to inject tenant_id automatically into every query
Schema per Tenant: The Middle Ground
PostgreSQL supports multiple schemas in one database. Each tenant gets their own schema (tenant_abc) with their own tables.
- Advantages: stronger isolation without the complexity of separate databases
- Migrations become a challenge — updating 100 schemas requires reliable automation
- Cross-tenant analytics (reporting) is harder — requires UNION or a separate analytics database
- Use Flyway or custom scripts with transactions for schema migrations
Subdomain Routing
academy-one.yourplatform.com and academy-two.yourplatform.com — how does this work technically?
- Wildcard DNS: *.yourplatform.com points to the same server
- Nginx/Caddy: extracts subdomain from the Host header and passes it to the app
- Middleware: extracts tenant_id from subdomain and attaches it to every request
- Custom domains: tenant uses their own academy.com — DNS CNAME to your server
- SSL: wildcard certificate with Let's Encrypt covers all subdomains
Multi-Tier Billing with Stripe
Each tenant has a different plan — Basic, Pro, Enterprise. Stripe Billing simplifies this dramatically.
- One Stripe Customer per tenant — not per individual user
- Stripe Subscription with Metered Billing for academies paying per student count
- Stripe webhooks update plan_id in your database on any plan change
- Feature flags tied to plan: tenant.features.aiTutor = plan === 'enterprise'
- Usage tracking: record monthly student count for tiered billing
