How it works · Multi-tenancy

Resolve the tenant once; everything else routes on it

One deployment serves many customers. The tenant is checked against the caller's token and put in the request context, and from there configuration, behaviour, writes, reads and background work each route themselves. Business code never mentions the tenant.

Multi-tenancy: one deployment, every tenant isolated A user signs in to their tenant's identity realm and calls a service with the tenant in x-chenile-tenant-id. The security filter verifies the token against that tenant's realm, so the header cannot be borrowed. The tenant is copied into the request context once; from there cconfig merges the tenant's configuration, the workflow can pick a tenant's own action, JPA writes go through a routing DataSource to the tenant's database, queries use the tenant's query store, and the outbox runs background work with the tenant pinned. A variant shows a forged tenant header being rejected. acme usertoken issued by realm acme security filterrealm = x-chenile-tenant-id validate-copy-headersx- headers → context ContextContainertenant acme configurationcconfig: acme/ layersworkflow behaviouracmeOrderCreate?writesTenantRoutingDataSourcereadsQueryTenantResolverbackground workTenantAwareOutboxPoller acme database orders · query views · outbox beta database orders · query views · outbox one routing DataSource, a pool per tenant (chenile.multids) business code never mentions the tenant
tenant
request
view
Step 1

Exchange

Payload

The header must match the token

The tenant header picks the identity realm whose keys verify the token, so a user cannot claim another tenant by changing a header.

Database per tenant, no routing code

One DataSource routes every connection to the tenant's pool, and queries have their own tenant routing. An unknown tenant fails instead of landing in someone else's database.

Bespoke without branches

A tenant's configuration is a layer over the defaults, and a tenant's behaviour is a bean with its prefix. No if statements on the tenant.