We’re turning the platform into a true multi-tenant SaaS and need a backend foundation that guarantees strict tenant isolation and fair resource usage. Requirements:
1) Data isolation: All data access through our Django app must be automatically scoped to the authenticated tenant extracted from the OAuth2 JWT. Implement a global mechanism so ORM queries are transparently filtered by tenant_id, preventing any cross-tenant leakage.
2) Governance and throttling: Add a Django middleware that evaluates incoming requests, estimates query cost, and enforces plan-based limits (e.g., max concurrent queries and max query runtime). When a tenant exceeds limits, return 429 Too Many Requests (include Retry-After). Track per-tenant consumption in near real time and surface metrics quickly, leveraging a metrics store such as Elasticsearch.
This is an internal platform capability focused on correctness, safety, and observability rather than UI.