Multi-Tenant SaaS Architecture Rules

Multi-Tenant SaaS Architecture Rules

Lays down a backend architect's rules for building multi-tenant B2B SaaS: tenant_id scoping, row-level security, per-tenant limits, isolation tests and safe ids.

Multi-Tenant SaaS taste of a backend architect who builds B2B products

  • Start with a shared database and a tenant_id column on every tenant-owned table; move to schema- or database-per-tenant only for a proven need. Confidence: 0.85
  • Make tenant_id NOT NULL and part of every composite index and unique constraint on tenant tables. Confidence: 0.90
  • Enforce isolation in the database with Postgres row-level security, not only in application code. Confidence: 0.85
  • Resolve the tenant once per request from the authenticated session or token, never from a client-supplied header or body field. Confidence: 0.95
  • Carry the tenant in a request context and have the data layer scope every query automatically. Confidence: 0.85
  • Write a test for each endpoint that proves a user from tenant A gets 404 for tenant B's resources. Confidence: 0.90
  • Return 404 instead of 403 for another tenant's resources so ids don't leak existence. Confidence: 0.80
  • Use non-guessable ids (UUIDv7 or prefixed random ids) for anything shown in URLs. Confidence: 0.85
  • Model users and organizations separately with a membership table, so one user can belong to many tenants. Confidence: 0.90
  • Keep roles per membership (owner, admin, member) and check permissions against the membership, not the user. Confidence: 0.85
  • Include tenant_id in every cache key, queue message, log line and metric label. Confidence: 0.90
  • Prefix object storage paths with the tenant id and issue only short-lived signed URLs. Confidence: 0.85
  • Apply rate limits and quotas per tenant so one noisy customer can't degrade everyone else. Confidence: 0.85
  • Drive plan limits and features from a per-tenant entitlements record, not scattered if plan == "pro" checks. Confidence: 0.80
  • Run background jobs with an explicit tenant argument; no job ever processes "all tenants" in one unscoped query. Confidence: 0.80
  • Run migrations once for the shared schema and keep them backward compatible, since all tenants upgrade together. Confidence: 0.80
  • Support tenant-level data export and hard deletion from day one; enterprise customers and GDPR will ask. Confidence: 0.85
  • Keep an audit log per tenant of admin actions, logins and permission changes, visible to tenant admins. Confidence: 0.80
  • Offer SSO (SAML/OIDC) and SCIM provisioning as tenant settings, not one-off custom code per customer. Confidence: 0.75
  • Let support staff impersonate a tenant user only with an explicit, logged, time-limited session. Confidence: 0.85
  • Track usage and cost per tenant so pricing decisions are based on real data. Confidence: 0.75
  • Avoid per-tenant code branches; express customer differences as configuration. Confidence: 0.80

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…