skills/multi-tenant-architecture-expert/SKILL.md
Tenant isolation, row-level security, shared/siloed schema patterns for SaaS platforms. Activate on: multi-tenant, tenant isolation, RLS, shared database, SaaS architecture, tenant context, data isolation. NOT for: connection pooling (use database-connection-pool-manager), API gateway routing (use api-gateway-reverse-proxy-expert).
npx skillsauth add curiositech/windags-skills multi-tenant-architecture-expertInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Design and implement multi-tenant SaaS systems with proper data isolation, tenant context propagation, and noisy neighbor prevention.
Activate on: "multi-tenant", "tenant isolation", "RLS", "shared database", "SaaS architecture", "tenant context", "data isolation", "noisy neighbor", "tenant onboarding"
NOT for: Connection pool sizing → database-connection-pool-manager | API gateway tenant routing → api-gateway-reverse-proxy-expert | Authorization framework → relevant auth skill
| Domain | Technologies | |--------|-------------| | Database RLS | PostgreSQL RLS, Supabase RLS, Neon branch-per-tenant | | Schema Isolation | PostgreSQL schemas, schema_search_path | | Tenant Context | AsyncLocalStorage (Node), cls-hooked, middleware injection | | ORMs | Prisma multi-schema, Drizzle with RLS, TypeORM tenant scope | | Infrastructure | Kubernetes namespaces, AWS Organizations, tenant-aware CDN |
-- Enable RLS on all tenant tables
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
-- Policy: tenants see only their own data
CREATE POLICY tenant_isolation ON orders
USING (tenant_id = current_setting('app.current_tenant')::uuid);
-- Set tenant context per request (from middleware)
SET LOCAL app.current_tenant = 'tenant-uuid-here';
-- All queries now automatically filtered
SELECT * FROM orders; -- only returns current tenant's orders
import { AsyncLocalStorage } from 'node:async_hooks';
interface TenantContext { tenantId: string; plan: 'free' | 'pro' | 'enterprise'; }
const tenantStore = new AsyncLocalStorage<TenantContext>();
// Middleware: extract tenant from JWT and propagate
function tenantMiddleware(req: Request, res: Response, next: NextFunction) {
const tenantId = req.auth?.tenantId; // from JWT
if (!tenantId) return res.status(403).json({ error: 'Tenant required' });
const ctx: TenantContext = { tenantId, plan: req.auth.plan };
tenantStore.run(ctx, () => {
// Set PostgreSQL session variable for RLS
req.db.query(`SET LOCAL app.current_tenant = $1`, [tenantId]);
next();
});
}
// Anywhere in the stack:
export function getCurrentTenant(): TenantContext {
const ctx = tenantStore.getStore();
if (!ctx) throw new Error('No tenant context — called outside request?');
return ctx;
}
Shared DB + RLS Schema/Tenant DB/Tenant
Cost per tenant Lowest Medium Highest
Data isolation Row-level Schema-level Full
Compliance Moderate Good Best
Migration effort Single migration Per-schema Per-database
Max tenants 10,000+ 1,000 100
Cross-tenant query Easy Possible Hard
Noisy neighbor Risk (mitigate) Moderate None
/api/tenant-123/orders lets users guess other tenant IDs; use JWT claims insteadcache:orders:123 is wrong, cache:tenant-abc:orders:123 is righttools
Building resilient distributed systems with circuit breakers, retries with full-jitter exponential backoff, retry budgets (per-request 3-attempt + per-client 10% ratio per Google SRE), deadline propagation, and the cascading-failure math (4 layers × 3 retries = 64x amplification). Grounded in Resilience4j, Microsoft Cloud Patterns, AWS Architecture Blog (Marc Brooker), and Google SRE Book.
testing
Designing HTTP cache headers that work correctly across browsers, CDNs, and shared proxies — `Cache-Control` directives per RFC 9111, `stale-while-revalidate` and `stale-if-error` per RFC 5861, the Vary header for varying responses, and surrogate keys for tag-based purging. Grounded in IETF RFCs and Cloudflare/Fastly docs.
development
Use when designing or fixing a Content Security Policy on a real site, choosing between nonce-based and hash-based CSP, adding strict-dynamic, debugging "Refused to execute inline script" errors, deploying CSP in report-only mode first, configuring report-to / report-uri, or auditing an existing policy for unsafe-inline / unsafe-eval / wildcards. Triggers: "CSP blocks legitimate inline script", strict-dynamic, nonce-{RANDOM}, sha256-{HASH}, object-src none, base-uri none, frame-ancestors, Trusted Types, X-Content-Security-Policy obsolete, report-only vs enforced. NOT for general HTTP security headers (HSTS, COOP/COEP), Trusted Types deep dive, CORS configuration, or building a WAF.
tools
Choosing and operating an HTTP API versioning strategy that doesn't break clients — Stripe's date-based pinned versions, the Deprecation/Sunset header pair (RFC 9745 + RFC 8594), URI vs header vs media-type approaches, and the version-transformer pattern. Grounded in Stripe's published architecture and IETF RFCs.