Tenant lifecycle
The provisioning saga, offboarding and shards.

State machine
REQUESTED → PROVISIONING → ACTIVE ⇄ SUSPENDED → OFFBOARDING → ERASED
↕
PROVISIONING_FAILED (retry resumes at the failed step)
| State | Meaning | Allowed transitions |
|---|---|---|
| REQUESTED | Row exists, nothing built | → PROVISIONING |
| PROVISIONING | Saga running (one job, serialized per tenant) | → ACTIVE, → PROVISIONING_FAILED |
| PROVISIONING_FAILED | Needs retry or operator cleanup | → PROVISIONING (POST /tenants/{id}/retry), → OFFBOARDING |
| ACTIVE | Serving | → SUSPENDED, → OFFBOARDING |
| SUSPENDED | Org deactivated, stacks stopped, data retained | → ACTIVE, → OFFBOARDING |
| OFFBOARDING | Teardown + erase running | → ERASED (a dead-lettered offboarding is retried in this state, see below) |
| ERASED | All data and keys destroyed; slug quarantined 90 days | — |
The table is the single transition table in code (TRANSITIONS); every status
change goes through transitionTenant, which updates WHERE status = <from> and
answers 409 when the tenant moved concurrently. REQUESTED → PROVISIONING is
done by the worker when it picks up the job, not by the API. In the prototype
the suspend/resume transitions exist in the table but no endpoint or saga uses
them yet.
Provisioning saga
Input: { name, slug, tier, modules[], adminEmail, region }.
A new tenant’s slug that matches a platform name (a platform host such as id or cockpit, meet/chat/console, look-alikes such as www or admin, and fortspace, fortspace-platform, fortspace-broker) is refused (parseNewSlug, control-plane PR #10); existing slugs are not re-checked.
Every step is create-or-get, records its result in provisioning_runs, and has
a compensation (right-hand column of the diagram).
- Request (
POST /admin/v1/tenants, before the saga): in one transaction the tenant row (REQUESTED, slug unique, onlystandard/eu/meetare accepted for now), its modules, the queued run, the audit row and the job. - Reserve (
reserve): choose the least loaded shard (tenant_count < max_tenants, status ACTIVE) and count the tenant on it in the same transaction that writesdb_shard_id,db_nameandbucketon the row, so a crashed step does not leak a slot (the retry keeps the one already set). With no capacity the step fails (no shard with capacity); theshard.addjob that would grow the pool is not built yet. - Infisical (
secrets): thetenant-secrets/<slug>.basePulumi stack: projecttenant-<slug>with folders/tenants/<slug>/{meet,chat}, machine identity<slug>-stackas viewer on that project only, the generated secrets (OIDC_STORE_REFRESH_TOKEN_KEY,SESSION_SECRET,REDIS_PASSWORD, LiveKit placeholders; an existing value is kept). The identity’s bootstrap credentials go to/platform/tenant-bootstrap/<slug>(worker only); the client secret, shown once by Infisical, is kept in the encrypted state. - Zitadel (
identity): thetenant-identity/<slug>Pulumi stack: org; grants ofFortspace Workspace(member,team_lead,tenant_stack) andFortspace Console(tenant_admin); the org’s login policy; the go-meet clientmeet-<slug>(user-agent/PKCE, no secret, exact redirect and post-logout URIs; the back-channel logout URI only when thebackchannelLogoutflag is on, see 03; the Tuwunel OIDC client is not built yet); the stack service account (<slug>-stack, roletenant_stack, which the broker requires) and its key. The client id and the key are then written to Infisical (tenant-secrets/<slug>.identity; the key never appears in a step output). - RustFS: bucket
tenant-<slug>, lifecycle rules (a failure there only warns), default encryption only when SSE is enabled in the config (failure is then not swallowed), scoped access key = usertenant-<slug>with policytenant-<slug>-rwlimited to that bucket, key stored in Infisical (S3_ACCESS_KEY,S3_BUCKET,S3_ENDPOINT, andS3_SECRET_KEYlast). A scoped key that exists without its stored secret is safe to rotate: the user is deleted and recreated. - Shard:
CREATE DATABASE meet_<slug>owned by rolemeet_<slug>_app(hyphens in the slug become_),CONNECTonly for that role (PUBLIClosesCONNECTon the new database and onpostgresandtemplate1, which tenant roles would otherwise inherit),pg_trgm, a generated role password, andDATABASE_URLin Infisical; run go-meet migrations (cmd/migrate up). A role that exists without a stored URL gets a reset password. - Route: insert
room_routes(slug → internal go-meet URL) and a per-tenant webhook signing secret, stored in Infisical twice: stack copy at/tenants/<slug>/meet#WEBHOOK_SIGNING_SECRETand broker copy at/routing/webhook-secrets/<slug>#SECRET(projectfortspace-broker); the table’swebhook_secret_refpoints at the routing copy. - Coolify (
orchestrator): the tenant’s Coolify stack, deployed by Pulumi: projectfortspace-tenant-<slug>, environment, the tenant Compose template (go-meet, redis, tuwunel) and the env vars. Only the Infisical bootstrap identity (client id and a ref to the secret) and non-secret config are Coolify env vars; the values themselves are Pulumi secrets, encrypted in the checkpoint (ADR-021). Stack: Pulumi projecttenant, stack<slug>(ADR-022). The step is create-or-update (up): the stack config is set from the registry on every run, so a re-run reconciles a drifted stack instead of recreating it. - Domains (
domains):meet.<slug>.<platform-domain>,chat.<slug>…via wildcard record + Traefik routers. - Probes: OIDC discovery, stack health (go-meet, Tuwunel), and one real
broker call: the saga logs in as the tenant’s service account (JWT
profile) and asks the broker for a token for a synthetic room
<slug>__<uuid>(the broker accepts tenants inPROVISIONINGfor this reason). - Activate: invite the first tenant admin by email (Zitadel invitation),
state ACTIVE and the audit event in one transaction. The step is
re-runnable: an already
ACTIVEtenant is success, and the invitation is re-sent on every run on purpose (03).
Step keys, in order: reserve, identity, secrets, storage, database,
route, orchestrator, domains, probes, activate.
In the first prototype, the orchestrator step (7) renders and validates a placeholder Compose stack (
traefik/whoami+redis) through a fake orchestrator instead of deploying to Coolify (the tenant row recordsorchestrator_type = fake); the DNS step uses a fake DNS; go-meet migrations (5) are skipped. Zitadel, Infisical, RustFS, the shard Postgres and the broker probe are real. A provisioning whose retries are exhausted is compensated automatically (dead-letter handler: org, secrets project, bucket, database and role, room route are removed; a first failure is never compensated, the retry resumes). The tenant then ends inPROVISIONING_FAILEDand the operator retries or offboards.This phase moves step (7) to Pulumi (ADR-011): one stack per tenant (
organization/tenant/<slug>) managing the Coolify projectfortspace-tenant-<slug>, its environment, the compose service, the env vars and a per-tenant tag. The adapter, the port extension and the worker wiring are not built yet (control-plane plan P3–P5); until they are, the fake orchestrator above is still what runs.
Idempotency and concurrency
- Job key = tenant id (queue policy
stately) → at most one queued and one active job per tenant (also prevents Pulumi stack lock errors). - Steps check for existing resources by deterministic name before creating. Resources whose secret is shown only once (Infisical client secret, RustFS key, database role password, Zitadel service-account key) are written to Infisical straight away and repaired on retry if the write was lost.
- A job crash resumes from the last completed step (a step that already
succeeded is recorded
skipped, with its output copied); compensations run only when the retries are exhausted (dead-letter) and on offboarding. - Retry policy and dead letters: 04.
Suspension
Not in the prototype. The
ACTIVE ⇄ SUSPENDEDtransitions are in the transition table, and the broker already refuses to sign for any tenant that is notACTIVEorPROVISIONING, but there is no suspend endpoint, queue or saga yet. Note the 30 s principal cache in 10: a tenant that has just been suspended can still be authorized for up to that long.
- Zitadel: deactivate org (blocks new logins; existing ID tokens remain valid until expiry).
- go-meet: control plane calls a signed
POST /internal/admin/suspend→ flush Redis sessions, deny new room tokens (broker also refuses to sign). - Coolify: stop tenant stack (data volumes kept).
Resume reverses the order.
Offboarding and erasure
- Export (optional): tenant admin downloads recordings/transcripts (presigned), chat export via Matrix admin tooling.
- Stop stack, delete Coolify project (compose + volumes) (
stop-stack). DROP DATABASE … WITH (FORCE)(terminates the sessions atomically) andDROP ROLE; decrement the shard’stenant_countonce (database).- Empty the bucket (every object version, every delete marker, every
unfinished multipart upload), delete it and its access key; delete the RustFS
SSE key if per-tenant keys are in use (
storage). - Delete Infisical project
tenant-<slug>(a hard delete: a soft delete would keep the slug reserved), the stack identity, the routing copy/routing/webhook-secrets/<slug>and the bootstrap copy/platform/tenant-bootstrap/<slug>(secrets). - Zitadel: delete the meet app, deactivate and delete the org (users, apps,
service accounts) (
identity). - Destroy the tenant backup key; older encrypted backups become unreadable (not in the prototype: no backups yet).
- Remove the room route and the DNS records (
routes); the Coolify step (stop-stack) runs Pulumidestroyand then removes the stack, so the Coolify project, its containers and its volumes are gone and no state row is left inpulumi_state. In the prototype the step still uses the fake orchestrator (Pulumi not in the prototype yet). - State ERASED,
erased_at, orchestrator reference cleared, audit entry (ids + timestamps only) in one transaction (erase).
Every delete target is derived from the slug (deterministic names), never
only from a registry column, so a crash between an external create and the
column write cannot leak a resource. Nothing is skipped silently: a missing
shard row or admin DSN fails the step (and the job goes to the dead-letter
queue and an operator) instead of releasing the slot while the database lives
on. The shard slot is released under a row lock and only while db_shard_id is
still set, so a re-run cannot count it back twice.
If offboarding exhausts its retries the tenant stays OFFBOARDING (its
resources may still exist) and the run is failed. The operator calls
POST /tenants/{id}/offboard again: since OFFBOARDING only allows ERASED,
that call changes no status; it adds a new run, an audit row
(tenant.retry-offboarding) and a job, and is refused while a run is pending
or after it succeeded. The saga resumes at the failed step.
A tenant can ask for an erasure certificate: the audit trail of steps with timestamps and resource ids.
Prototype note: the tenant row is kept after erasure (ERASED, erased_at set)
and its slug is never reused, which is stricter than the 90-day quarantine.
Shard management
| Operation | Trigger | How |
|---|---|---|
| Add shard | No ACTIVE shard under capacity | Create Postgres + PgBouncer as a new Coolify app in fortspace-data-pool, register in db_shards (prototype: an operator registers it with POST /admin/v1/shards, which writes an audit row; the admin DSN must already be in Infisical, and the adminSecretRef must be a /platform/shards/… ref) |
| Mark FULL | tenant_count >= max_tenants |
Allocator skips it |
| Relocate tenant | Noisy neighbor, tier change | Set tenant read-only → pg_dump → restore on target → switch db_shard_id + env → redeploy → verify → drop source |
| Migrate schema | go-meet release | Parallel workers (bounded, e.g. 10), schema_version per tenant tracked in registry |
Defaults from the discussions: max_tenants=50, go-meet pool max_open_conns=3,
PgBouncer in transaction mode with small default pool; identical Postgres major
versions across core and shards.
Upgrades
- Tenant stacks pin image tags per module in
tenant_modules.version. - Rollouts: canary tenant(s) → ring of 10% → all. Each rollout is a job that
runs migrations, redeploys, probes, and can roll back via Coolify
(
rollback). - Zitadel and LiveKit upgrades are platform changes handled outside tenant jobs, with their own maintenance windows.