Use Case

Multi-tenant SaaS ClickHouse analytics with policy control by default

This is the path for teams whose analytics already reach customers. The goal is not only faster queries. It is a backend path where tenant scope and role checks stop being easy to forget.

Tenancy mode

Scoped automatically

Policy location

Inside query code

Scale target

2 to 2000+ tenants

Map auth once

Turn API keys or sessions into typed request context with tenant and role metadata in one place.

Inject tenant filters

Configure extraction once and let the standard query path apply tenant scope instead of trusting every author to remember it.

Enforce roles inline

Keep sensitive access checks next to the query definition instead of scattering them through route files.

Request lifecycle

1

Request arrives with API key/session.

2

Auth strategy resolves tenant and roles.

3

Tenant scope is injected into query execution.

4

Role gates are enforced in definitions.

5

Typed responses return safe tenant data.

Tenant auth without glue code

Map incoming auth to one typed context object so tenant and role data enter the system in a predictable way.

auth.ts

Automatic tenant scoping

Set tenant extraction once and let the backend query path apply it consistently rather than relying on repeated manual filters.

api.ts

Role-based access for sensitive queries

Put the access rule on the query definition that needs it instead of treating authorization as an afterthought outside the analytics layer.

queries.ts

Governance outcome

Clear tenant boundaries with a single shared query layer

  • Clear admin versus tenant capabilities
  • Reusable auth and policy primitives
  • One reviewable backend path for customer-facing analytics