Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Multi Tenancy?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/adityaaatiwari-multi-tenancy)
---
description: Architect B2B SaaS multi-tenancy safely using strict tenant scoping, database RLS, cache isolation, and noisy-neighbor limits
profile: standard
tags: architecture, database, security, backend
---
# Multi-tenancy
Use when building multi-tenant B2B APIs, storage schemas, background queues, or caches.
## Tenant isolation
- Derive the active `tenantId` solely from verified auth credentials/tokens—never trust client-supplied body fields or query parameters alone.
- Enforce isolation at the database boundary (for example PostgreSQL Row-Level Security policies with transaction-scoped `SET LOCAL` + composite `(tenant_id, id)` indexes) as defense in depth behind app filters.
- Prefix all Redis cache keys, object storage paths, and search index queries with `tenantId`.
## Fair usage and background jobs
- Carry explicit `tenantId` context inside every queued job payload and verify object ownership before executing mutations.
- Apply per-tenant rate limits and concurrency/queue fairness so one heavy tenant does not starve others.
## Verify
Write cross-tenant integration tests attempting reads, updates, deletes, and cache lookups across Tenant A and Tenant B records and assert `403`/`404`.