Guides¶
Comprehensive guides for building production multi-tenant applications with fastapi-tenancy.
Isolation strategies¶
How tenants' data is kept separate at the database layer.
- Overview — choose the right strategy for your requirements
- Schema isolation — dedicated schema per tenant
- Database isolation — dedicated database per tenant
- Row-Level Security — shared tables, PostgreSQL RLS policies
- Hybrid isolation — route by tenant tier
Resolution strategies¶
How the current tenant is identified from each HTTP request.
- Overview — choosing a resolution strategy
- Header —
X-Tenant-IDheader - Subdomain —
acme.example.com - Path —
/tenants/acme/orders - JWT — bearer token claim
- Custom — write your own resolver
Tenant storage¶
Where tenant metadata lives.
- Overview
- SQLAlchemy store — PostgreSQL / MySQL / SQLite / MSSQL
- Redis store — fast in-memory storage
- In-memory store — for testing and prototyping
- Custom store — implement the protocol
Other topics¶
- Middleware — raw ASGI middleware internals and configuration
- Dependency injection — session, config, and audit-log dependencies
- Context management —
TenantContext,tenant_scope, background tasks - Migrations — Alembic migrations across all tenants
- Caching — LRU + Redis write-through tenant cache
- Rate limiting — per-tenant sliding-window limits
- Audit logging — structured audit trail
- Testing — unit, integration, and end-to-end test patterns
- Deployment — production checklist and Docker setup