SaaS Architecture Advisor
Overview
This skill helps teams design and implement multi-tenant SaaS architectures by evaluating isolation strategies, generating tenant routing patterns, and recommending the right tradeoffs based on scale, compliance requirements, and budget constraints.
Instructions
Step 1: Gather Context
Before recommending anything, establish:
- Scale: Expected tenant count (year 1 and year 3)
- Tenant size: Users per tenant (range and distribution)
- Compliance: SOC2, HIPAA, GDPR, or contractual isolation requirements
- Stack: Database, language, framework, hosting
- Budget: Monthly infrastructure budget
- Data sensitivity: What kind of data tenants store
- Customization needs: Do tenants need custom fields, workflows, or branding?
Step 2: Evaluate Tenancy Models
Present trade-offs for these models:
Shared Everything (single DB, shared tables, tenant_id column):
- Best for: <1,000 tenants, uniform data model, no strict isolation requirements
- Cost: Lowest ($1 DB serves all tenants)
- Risk: Query bugs can leak data; noisy neighbor issues
- Mitigation: Row-level security (PostgreSQL RLS), application-layer checks
Schema per Tenant (single DB, separate schemas):
- Best for: 50-500 tenants, moderate isolation needs
- Cost: Low (single DB instance, logical separation)
- Risk: Migration complexity scales with tenant count; catalog bloat
- Mitigation: Automated migration tooling, connection pooling with schema switching
Database per Tenant (dedicated DB per tenant):
- Best for: <100 tenants, strict compliance, large enterprise clients
- Cost: Highest ($274+/mo per tenant on RDS)
- Risk: Operational overhead managing N databases
- Mitigation: Infrastructure-as-code templates, centralized monitoring
Hybrid (shared for standard, dedicated for enterprise):
- Best for: Mixed tenant base with some requiring isolation
- Cost: Moderate (shared DB + N dedicated for premium)
- Trade-off: Two code paths, but repository pattern abstracts them
Step 3: Design Tenant Routing
Recommend routing strategy based on the application type:
- Subdomain routing:
tenant.app.com — best for B2B SaaS
- Path routing:
app.com/tenant/ — simpler SSL, good for internal tools
- Header routing:
X-Tenant-ID — API-first products
- JWT claim:
tenant_id in token — serverless/stateless architectures
Step 4: Address Cross-Cutting Concerns
For each recommendation, cover:
- Rate limiting: Per-tenant to prevent noisy neighbors
- Billing metering: How to track usage per tenant
- Background jobs: Tenant context propagation to workers/queues
- Caching: Tenant-namespaced cache keys
- Search: Filtered indices or per-tenant indices
- Audit logging: Tenant-scoped audit trails
Step 5: Generate Implementation Artifacts
Produce:
- Database schema with tenant isolation mechanisms
- Middleware/interceptor code for tenant context
- Repository pattern that abstracts tenancy
- Tenant provisioning/deprovisioning scripts
- Migration strategy for existing single-tenant apps
Examples
Example 1: Early-Stage SaaS
User prompt:
We have 30 tenants and expect 200 in a year. PostgreSQL, no compliance needs yet. What tenancy model?
Agent output:
Recommendation: Shared database with RLS
At 200 tenants with no compliance requirements, a single PostgreSQL database
with row-level security gives you the best simplicity-to-isolation ratio.
Implementation:
1. Add tenant_id UUID column to all tenant-scoped tables
2. Enable RLS: ALTER TABLE <table> ENABLE ROW LEVEL SECURITY;
3. Create policies: USING (tenant_id = current_setting('app.tenant_id')::UUID)
4. Set tenant context per request in middleware via SET LOCAL
Cost: Single db.t3.medium handles this easily at ~$50/month.
Migration path: If you later need dedicated DBs for enterprise clients,
the repository pattern lets you route specific tenants without changing app code.
Example 2: Healthcare SaaS Requiring HIPAA
User prompt:
Building a patient records SaaS. 50 clinic tenants, HIPAA required. Budget: $5k/month infra.
Agent output:
Recommendation: Database per tenant
HIPAA requires demonstrable data isolation. At 50 tenants, per-tenant databases
are operationally feasible and satisfy compliance auditors.
Architecture:
- Tenant registry DB (shared): Stores tenant metadata + routing config
- Per-tenant RDS instances: db.t3.medium ($50/mo each) = $2,500/mo for 50
- Connection routing: Middleware resolves tenant → connection string from registry
- Encryption: RDS encryption at rest + tenant-specific KMS keys
Budget fit: $2,500 for DBs + $1,000 compute + $500 other = $4,000/mo ✅
Key HIPAA controls addressed:
- Physical data isolation (separate DB instances)
- Per-tenant encryption keys (KMS)
- Tenant-scoped audit logs
- Independent backup/restore per tenant
Guidelines
- No one-size-fits-all — always evaluate against the specific context before recommending
- Start simple, migrate up — recommend the simplest model that meets requirements; overengineering multi-tenancy is expensive
- RLS is not optional for shared databases — application-layer filtering alone is insufficient; one missed WHERE clause = data breach
- Test tenant isolation — always recommend integration tests that verify queries cannot access other tenants' data
- Plan for the migration path — even if starting with shared DB, design the data access layer so switching to dedicated DBs later is feasible
- Background jobs are the blind spot — tenant context often gets lost in async flows; always address this explicitly
1---2name: saas-architecture-advisor3description: >-4 Advises on multi-tenant SaaS architecture decisions including tenancy5 models, data isolation strategies, tenant routing, and scaling patterns.6 Use when someone is building a SaaS product, converting single-tenant to7 multi-tenant, or evaluating isolation strategies. Trigger words: multi-tenant,8 SaaS architecture, tenant isolation, shared database, per-tenant database,9 row-level security, tenant routing, SaaS patterns.10license: Apache-2.011compatibility: "Language and database agnostic; examples default to PostgreSQL and Node.js"12metadata:13 source: https://skillmd.com/skills/eliferjunior/saas-architecture-advisor14 author: terminal-skills15 version: "1.0.0"16 category: development17 tags: ["saas", "multi-tenant", "architecture", "database-design"]18---1920# SaaS Architecture Advisor2122## Overview2324This skill helps teams design and implement multi-tenant SaaS architectures by evaluating isolation strategies, generating tenant routing patterns, and recommending the right tradeoffs based on scale, compliance requirements, and budget constraints.2526## Instructions2728### Step 1: Gather Context2930Before recommending anything, establish:31- **Scale**: Expected tenant count (year 1 and year 3)32- **Tenant size**: Users per tenant (range and distribution)33- **Compliance**: SOC2, HIPAA, GDPR, or contractual isolation requirements34- **Stack**: Database, language, framework, hosting35- **Budget**: Monthly infrastructure budget36- **Data sensitivity**: What kind of data tenants store37- **Customization needs**: Do tenants need custom fields, workflows, or branding?3839### Step 2: Evaluate Tenancy Models4041Present trade-offs for these models:4243**Shared Everything** (single DB, shared tables, tenant_id column):44- Best for: <1,000 tenants, uniform data model, no strict isolation requirements45- Cost: Lowest ($1 DB serves all tenants)46- Risk: Query bugs can leak data; noisy neighbor issues47- Mitigation: Row-level security (PostgreSQL RLS), application-layer checks4849**Schema per Tenant** (single DB, separate schemas):50- Best for: 50-500 tenants, moderate isolation needs51- Cost: Low (single DB instance, logical separation)52- Risk: Migration complexity scales with tenant count; catalog bloat53- Mitigation: Automated migration tooling, connection pooling with schema switching5455**Database per Tenant** (dedicated DB per tenant):56- Best for: <100 tenants, strict compliance, large enterprise clients57- Cost: Highest ($274+/mo per tenant on RDS)58- Risk: Operational overhead managing N databases59- Mitigation: Infrastructure-as-code templates, centralized monitoring6061**Hybrid** (shared for standard, dedicated for enterprise):62- Best for: Mixed tenant base with some requiring isolation63- Cost: Moderate (shared DB + N dedicated for premium)64- Trade-off: Two code paths, but repository pattern abstracts them6566### Step 3: Design Tenant Routing6768Recommend routing strategy based on the application type:69- **Subdomain routing**: `tenant.app.com` — best for B2B SaaS70- **Path routing**: `app.com/tenant/` — simpler SSL, good for internal tools71- **Header routing**: `X-Tenant-ID` — API-first products72- **JWT claim**: `tenant_id` in token — serverless/stateless architectures7374### Step 4: Address Cross-Cutting Concerns7576For each recommendation, cover:77- **Rate limiting**: Per-tenant to prevent noisy neighbors78- **Billing metering**: How to track usage per tenant79- **Background jobs**: Tenant context propagation to workers/queues80- **Caching**: Tenant-namespaced cache keys81- **Search**: Filtered indices or per-tenant indices82- **Audit logging**: Tenant-scoped audit trails8384### Step 5: Generate Implementation Artifacts8586Produce:87- Database schema with tenant isolation mechanisms88- Middleware/interceptor code for tenant context89- Repository pattern that abstracts tenancy90- Tenant provisioning/deprovisioning scripts91- Migration strategy for existing single-tenant apps9293## Examples9495### Example 1: Early-Stage SaaS9697**User prompt:**98```99We have 30 tenants and expect 200 in a year. PostgreSQL, no compliance needs yet. What tenancy model?100```101102**Agent output:**103```104Recommendation: Shared database with RLS105106At 200 tenants with no compliance requirements, a single PostgreSQL database107with row-level security gives you the best simplicity-to-isolation ratio.108109Implementation:1101. Add tenant_id UUID column to all tenant-scoped tables1112. Enable RLS: ALTER TABLE <table> ENABLE ROW LEVEL SECURITY;1123. Create policies: USING (tenant_id = current_setting('app.tenant_id')::UUID)1134. Set tenant context per request in middleware via SET LOCAL114115Cost: Single db.t3.medium handles this easily at ~$50/month.116Migration path: If you later need dedicated DBs for enterprise clients,117the repository pattern lets you route specific tenants without changing app code.118```119120### Example 2: Healthcare SaaS Requiring HIPAA121122**User prompt:**123```124Building a patient records SaaS. 50 clinic tenants, HIPAA required. Budget: $5k/month infra.125```126127**Agent output:**128```129Recommendation: Database per tenant130131HIPAA requires demonstrable data isolation. At 50 tenants, per-tenant databases132are operationally feasible and satisfy compliance auditors.133134Architecture:135- Tenant registry DB (shared): Stores tenant metadata + routing config136- Per-tenant RDS instances: db.t3.medium ($50/mo each) = $2,500/mo for 50137- Connection routing: Middleware resolves tenant → connection string from registry138- Encryption: RDS encryption at rest + tenant-specific KMS keys139140Budget fit: $2,500 for DBs + $1,000 compute + $500 other = $4,000/mo ✅141142Key HIPAA controls addressed:143- Physical data isolation (separate DB instances)144- Per-tenant encryption keys (KMS)145- Tenant-scoped audit logs146- Independent backup/restore per tenant147```148149## Guidelines150151- **No one-size-fits-all** — always evaluate against the specific context before recommending152- **Start simple, migrate up** — recommend the simplest model that meets requirements; overengineering multi-tenancy is expensive153- **RLS is not optional for shared databases** — application-layer filtering alone is insufficient; one missed WHERE clause = data breach154- **Test tenant isolation** — always recommend integration tests that verify queries cannot access other tenants' data155- **Plan for the migration path** — even if starting with shared DB, design the data access layer so switching to dedicated DBs later is feasible156- **Background jobs are the blind spot** — tenant context often gets lost in async flows; always address this explicitly