Prompt
I'm building a multi-tenant SaaS platform and need tenant isolation, audit logging, and SSO. What should I use?
Latest observation
For a multi-tenant SaaS, you’ll usually want three separate layers:
- Tenant isolation
- Audit logging
- SSO / identity federation
There isn’t one single product that does all of this perfectly for every stack, so the best choice depends on your architecture. Here’s the practical breakdown.
1) Tenant isolation: what to use
Best common options
-
Shared app + shared DB + tenant_id column
- Most common for SaaS.
- Lowest operational cost.
- Works well if you enforce isolation in the app and DB.
- Add row-level security if your DB supports it (e.g., PostgreSQL RLS).
-
Shared app + separate schema per tenant
- Better isolation than just
tenant_id. - More operational complexity.
- Good when tenants need stronger separation but you still want one app.
- Better isolation than just
-
Separate database per tenant
- Strongest isolation.
- Best for enterprise/compliance-heavy customers.
- Highest ops overhead.
- Often used for larger customers only.
Recommendation
- Start with shared app + shared DB + PostgreSQL Row-Level Security (RLS) if possible.
- Move to schema-per-tenant or database-per-tenant only for premium/compliance tenants.
2) Audit logging: what to use
You want an audit system that records:
- who did it
- what they did
- when it happened
- tenant/account context
- before/after values when relevant
- source IP / user agent / request ID
Best practice
Use an append-only audit log with:
- immutable writes
- centralized storage
- searchable retention
- tamper resistance
Good implementation options
- Application-level audit events written to a dedicated audit table or log stream
- Database triggers for critical data changes
- Event pipeline to a log store like:
- Elasticsearch / OpenSearch
- Datadog
- Splunk
- Cloud-native logging (CloudWatch, Stackdriver, Azure Monitor)
- Kafka + downstream storage
Recommendation
- Use application-level structured audit events for business actions.
- Add DB triggers for sensitive tables if you need stronger guarantees.
- Store audit records in a separate immutable audit store.
3) SSO: what to use
For B2B SaaS, you typically want:
- SAML 2.0 for enterprise customers
- OpenID Connect (OIDC) for modern identity providers
- SCIM for automated user provisioning/deprovisioning
Best identity approaches
Option A: Use an identity platform
If you want speed and less maintenance, use:
- Auth0
- Okta
- WorkOS
- Clerk (more app-focused, less enterprise-heavy than WorkOS/Auth0)
- Azure AD / Entra ID integration via OIDC/SAML
- AWS Cognito if you’re already in AWS, though enterprise SSO can be less pleasant
Option B: Build your own IdP integration
If you have strong security engineering resources, integrate directly with:
- OIDC
- SAML
- SCIM
This gives flexibility but adds complexity.
Recommendation
For a B2B multi-tenant SaaS, the most common practical choice is:
- WorkOS if you want enterprise SSO + SCIM quickly
- Auth0 if you want a broader identity platform
- Okta if identity is core and you need strong enterprise workflows
A solid default stack
If I had to recommend a straightforward setup:
- Tenant isolation: PostgreSQL +
tenant_id+ Row-Level Security - Audit logging: structured audit events in a separate append-only store
- SSO: WorkOS or Auth0 with SAML + OIDC + SCIM
Important design tips
- Put
tenant_idon every tenant-owned table - Enforce tenant context at the data-access layer and DB layer, not just in UI
- Never rely on the frontend for isolation
- Use separate encryption keys or key namespaces per tenant if compliance matters
- Include
tenant_id,actor_id,request_id, andcorrelation_idin every audit event - Plan for tenant offboarding:
- data export
- retention policy
- deletion policy
- SSO disconnect
- audit retention
If you want the shortest answer
Use:
- PostgreSQL RLS for tenant isolation
- Append-only structured audit logging
- WorkOS/Auth0 for SSO and SCIM
If you want, I can also give you:
- a reference architecture for this,
- a database schema pattern for tenant isolation and audit logs, or
- a vendor comparison of WorkOS vs Auth0 vs Okta.