Prompt

multi tenant saas architecture auth billing observability

Technology / Cloud Infrastructure1 observationLast seen Oct 23, 2026

Latest observation

Oct 23, 2026OpenAI APIWeb search: off

Here’s a practical multi-tenant SaaS architecture view of auth, billing, and observability.

1) Core architecture shape

A common layout:

  • Frontend
  • API Gateway / BFF
  • Auth service / identity provider
  • Tenant service (tenant metadata, plans, limits)
  • Core app services (business logic)
  • Billing service
  • Observability stack
  • Shared infrastructure
    • DB(s)
    • cache
    • message bus
    • object storage

Key concept: every request should resolve to:

  • who is the user?
  • which tenant are they in?
  • what can they do?
  • is the tenant allowed to use this feature?

2) Multi-tenancy models

A. Shared DB, shared schema

  • All tenants share the same tables.
  • Every row has tenant_id.

Pros

  • Cheapest
  • Easiest to operate initially
  • Great for many small tenants

Cons

  • Strong need for tenant isolation in code
  • Harder to do per-tenant performance tuning
  • Risk of accidental data leakage if queries miss tenant_id

B. Shared DB, separate schema

  • Each tenant gets its own schema.

Pros

  • Better isolation than row-based
  • Easier tenant-specific migrations than separate DBs sometimes

Cons

  • More operational overhead
  • Schema migrations become more complex

C. Separate DB per tenant

  • Strong isolation, best for enterprise or regulated customers.

Pros

  • Best isolation
  • Easier compliance story
  • Easier noisy-neighbor control

Cons

  • Operationally expensive
  • Harder migrations at scale

Recommended default

For most SaaS products:

  • start with shared DB + tenant_id
  • design abstraction so you can later move high-value tenants to dedicated DBs

3) Authentication and authorization

Authentication

Use an IdP such as:

  • Auth0
  • Clerk
  • Cognito
  • Azure AD / Entra ID
  • Keycloak

Typical flow:

  1. User logs in via IdP
  2. App receives JWT / session
  3. Backend validates token
  4. Backend resolves tenant membership

Authorization

You need two layers:

A. Tenant-level authorization

  • Is the user part of tenant X?
  • What role do they have in tenant X?

Examples:

  • owner
  • admin
  • member
  • billing_admin
  • read_only

B. Resource-level authorization

  • Can this user access this project/document/invoice within the tenant?

Best practice

Store membership like:

  • users
  • tenants
  • tenant_memberships(user_id, tenant_id, role)

If users can belong to multiple tenants, this is essential.

Token design

JWT should usually contain:

  • user id
  • auth context
  • maybe current tenant id
  • maybe roles/scopes

But avoid stuffing too much tenant-specific data into JWT if membership changes frequently.

Tenant resolution

Choose one:

  • subdomain: acme.app.com
  • path: /t/acme/...
  • header: X-Tenant-ID
  • domain mapping: acme.com

Subdomain is common and clean.


4) Billing architecture

Billing should be a separate bounded context.

Billing responsibilities

  • plan definitions
  • subscription lifecycle
  • usage metering
  • invoicing
  • payment processing
  • tax handling
  • dunning / failed payments
  • entitlements

Core objects

  • plan
  • subscription
  • invoice
  • payment_method
  • usage_record
  • entitlement

Flow

  1. Tenant subscribes to a plan
  2. Billing service creates subscription with Stripe/Paddle/etc.
  3. Billing service stores tenant’s plan/limits
  4. App checks entitlements on each request or caches them
  5. Usage events are emitted asynchronously
  6. Billing aggregates usage and bills accordingly

Important design choice: billing vs entitlements

Do not make every app request call the billing provider.

Instead:

  • billing provider = source of truth for payments
  • entitlement service/cache = source of truth for what tenant can use right now

Common billing patterns

Flat-rate SaaS

  • simpler
  • just check active subscription

Usage-based SaaS

  • track meter events
  • aggregate usage daily/hourly
  • send to billing provider

Hybrid

  • base subscription + usage overage

Practical advice

Use a payment processor like:

  • Stripe Billing
  • Paddle
  • Chargebee

And keep your own internal:

  • tenant plan state
  • entitlements
  • usage ledger

5) Observability

Observability should be tenant-aware.

Three pillars

  • logs
  • metrics
  • traces

Required tags/labels

Every signal should include:

  • tenant_id
  • user_id if applicable
  • request_id
  • trace_id
  • service
  • environment

Logs

Use structured logs:

{
  "level": "info",
  "tenant_id": "t_123",
  "user_id": "u_456",
  "request_id": "req_789",
  "message": "Invoice generated"
}

Metrics

Track:

  • requests per tenant
  • latency per tenant
  • error rate per tenant
  • active users per tenant
  • billing usage per tenant
  • queue lag per tenant

Be careful: high-cardinality labels like tenant_id can explode metric cost. Use:

  • top tenants only
  • sampled metrics
  • aggregated buckets
  • separate dashboards for enterprise tenants

Traces

Include tenant context in trace attributes:

  • tenant.id
  • user.id
  • subscription.plan

Alerting

Useful alerts:

  • spike in 5xx for one tenant
  • payment failures
  • usage quota nearing limit
  • auth failures
  • data pipeline lag
  • tenant-specific latency regression

6) Data isolation and security

Must-haves

  • row-level tenant filtering in every query
  • automated tests for tenant isolation
  • RLS if using Postgres
  • encryption at rest
  • secrets isolation
  • audit logs for sensitive actions

Good patterns

  • enforce tenant scope in data access layer
  • never trust client-provided tenant_id alone
  • resolve tenant from authenticated session + tenant membership
  • use signed links or scoped tokens for tenant-specific resources

7) Recommended request flow

  1. User visits tenant subdomain
  2. Auth verifies identity
  3. Backend resolves tenant
  4. Backend checks membership and role
  5. Backend checks entitlements
  6. Request hits business service
  7. Service writes logs/traces with tenant context
  8. Async events go to billing/analytics pipeline

8) Suggested service boundaries

A clean split:

  • Identity/Auth
  • Tenant management
  • Entitlements
  • Billing
  • Core product APIs
  • Event ingestion / usage metering
  • Observability / audit pipeline

9) Tech stack example

One possible setup:

  • Frontend: Next.js
  • API: Node.js / NestJS or Go
  • Auth: Auth0 / Clerk / Keycloak
  • DB: Postgres + RLS
  • Cache: Redis
  • Queue: SQS / RabbitMQ / Kafka
  • Billing: Stripe
  • Metrics: Prometheus + Grafana
  • Logs: ELK / Loki
  • Tracing: OpenTelemetry + Tempo/Jaeger

10) Pitfalls to avoid

  • forgetting tenant_id in queries
  • using billing provider as your app authorization source
  • mixing auth and billing logic in the same service
  • putting high-cardinality tenant IDs into every metric without control
  • not modeling multi-tenant membership explicitly
  • not designing for plan/entitlement changes
  • relying only on frontend checks for access control

If you want, I can turn this into one of these:

  1. a reference architecture diagram
  2. a database schema
  3. a microservices vs monolith comparison
  4. a concrete AWS/GCP implementation
  5. a Stripe + Auth0 + Postgres design

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.