Designing Multi-Tenancy Architecture
1. Designing Database-per-Tenant Architecture
| Aspect | Detail |
|---|---|
| Isolation | Strongest; per-tenant DB |
| Backup / restore | Per tenant easy |
| Cost | High at scale |
| Cross-tenant queries | Hard |
| Best for | Few large enterprise tenants |
2. Designing Shared Database with Tenant Isolation
| Aspect | Detail |
|---|---|
| Tenant_id column | On every row |
| RLS | Postgres row-level security; defense-in-depth |
| App-enforced filter | Always WHERE tenant_id |
| Cost | Most efficient |
| Risk | Cross-tenant leak bug catastrophic |
3. Designing Schema-per-Tenant Architecture
| Aspect | Detail |
|---|---|
| Per-tenant schema | Same DB |
| Migration challenge | Apply across N schemas |
| Connection | Set search_path per request |
| Best for | Mid-tier isolation |
4. Designing Tenant Data Isolation
| Layer | Detail |
|---|---|
| Network | Per-tenant VPC for premium |
| Compute | Pool / silo / hybrid |
| Data | Encryption with per-tenant DEK |
| Logical | Tenant_id everywhere |
5. Designing Tenant Customization
| Mechanism | Detail |
|---|---|
| Config per tenant | Branding, features |
| Custom fields | JSONB / EAV / per-tenant table |
| Workflow customization | Templates / DSL |
| Plugin model | Extension points |
6. Designing Tenant Provisioning
| Step | Detail |
|---|---|
| Self-serve signup | Auto-create tenant |
| Resource allocation | Schema, queue, namespace |
| Default config | Plan-based |
| Idempotent | Safe retry |
| Workflow | Step-based with rollback |
7. Designing Cross-Tenant Operations
| Need | Detail |
|---|---|
| Aggregate analytics | Pipe to separate analytics store |
| Admin / support | Privileged audited access |
| Cross-tenant search | Avoid; use per-tenant indexes |
| Background jobs | Always include tenant_id |
8. Designing Tenant Rate Limiting
| Aspect | Detail |
|---|---|
| Per-tenant quota | Prevent noisy neighbor |
| Plan-based limits | Free / Pro / Enterprise |
| Burst allowance | Token bucket per tenant |
| Headers | Expose limit / remaining |
9. Designing Tenant Billing and Metering
| Element | Detail |
|---|---|
| Usage events | Captured per tenant |
| Aggregation | Hourly/daily rollup |
| Metering pipeline | Idempotent, audit-ready |
| Billing engine | Stripe Billing, Metronome, Orb |
| Invoice | Itemized usage |
10. Designing Tenant Migration
| Scenario | Detail |
|---|---|
| Pool → silo | For tier upgrade |
| Region migration | Compliance / latency |
| Process | Snapshot → copy → cutover → verify |
| Read-only window | Or dual-write |
11. Designing Tenant Resource Quotas
| Resource | Detail |
|---|---|
| Storage | Per-tenant cap |
| API calls | Per minute / day |
| Concurrent jobs | Worker share |
| Users / seats | Plan-based |
| Soft / hard limits | Warn vs reject |
12. Designing Tenant Onboarding
| Step | Detail |
|---|---|
| Signup flow | Email + verify |
| Provision tenant | Async if heavy |
| Sample data | Demo workspace |
| Integrations | OAuth connect to data sources |
| Activation tracking | Funnel analytics |