Authorization interview question · Most asked
How do you enforce tenant isolation in a multi-tenant SaaS?
Summary
Resolve the tenant from the authenticated session or token (never from an unchecked request parameter), and scope every query, cache key, file path and message by tenant, ideally enforced centrally (repository base filters or database row-level security).
Longer Answer
Postgres Row-Level Security with a session variable (SET app.tenant_id) adds a defense-in-depth backstop. Write automated tests that try cross-tenant access. Separate databases per tenant give stronger isolation at higher operational cost.
Key Points
- Tenant from trusted identity
- Scope queries, caches, storage
- Row-level security as backstop
- Cross-tenant access tests