Skip to content
Fortspace Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Tenant lifecycle

The provisioning saga, offboarding and shards.

Provisioning saga

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).

  1. Request (POST /admin/v1/tenants, before the saga): in one transaction the tenant row (REQUESTED, slug unique, only standard/eu/meet are accepted for now), its modules, the queued run, the audit row and the job.
  2. Reserve (reserve): choose the least loaded shard (tenant_count < max_tenants, status ACTIVE) and count the tenant on it in the same transaction that writes db_shard_id, db_name and bucket on 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); the shard.add job that would grow the pool is not built yet.
  3. Infisical (secrets): the tenant-secrets/<slug>.base Pulumi stack: project tenant-<slug> with folders /tenants/<slug>/{meet,chat}, machine identity <slug>-stack as 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.
  4. Zitadel (identity): the tenant-identity/<slug> Pulumi stack: org; grants of Fortspace Workspace (member, team_lead, tenant_stack) and Fortspace Console (tenant_admin); the org’s login policy; the go-meet client meet-<slug> (user-agent/PKCE, no secret, exact redirect and post-logout URIs; the back-channel logout URI only when the backchannelLogout flag is on, see 03; the Tuwunel OIDC client is not built yet); the stack service account (<slug>-stack, role tenant_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).
  5. 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 = user tenant-<slug> with policy tenant-<slug>-rw limited to that bucket, key stored in Infisical (S3_ACCESS_KEY, S3_BUCKET, S3_ENDPOINT, and S3_SECRET_KEY last). A scoped key that exists without its stored secret is safe to rotate: the user is deleted and recreated.
  6. Shard: CREATE DATABASE meet_<slug> owned by role meet_<slug>_app (hyphens in the slug become _), CONNECT only for that role (PUBLIC loses CONNECT on the new database and on postgres and template1, which tenant roles would otherwise inherit), pg_trgm, a generated role password, and DATABASE_URL in Infisical; run go-meet migrations (cmd/migrate up). A role that exists without a stored URL gets a reset password.
  7. 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_SECRET and broker copy at /routing/webhook-secrets/<slug>#SECRET (project fortspace-broker); the table’s webhook_secret_ref points at the routing copy.
  8. Coolify (orchestrator): the tenant’s Coolify stack, deployed by Pulumi: project fortspace-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 project tenant, 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.
  9. Domains (domains): meet.<slug>.<platform-domain>, chat.<slug>… via wildcard record + Traefik routers.
  10. 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 in PROVISIONING for this reason).
  11. 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 ACTIVE tenant 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 records orchestrator_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 in PROVISIONING_FAILED and the operator retries or offboards.

This phase moves step (7) to Pulumi (ADR-011): one stack per tenant (organization/tenant/<slug>) managing the Coolify project fortspace-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 ⇄ SUSPENDED transitions are in the transition table, and the broker already refuses to sign for any tenant that is not ACTIVE or PROVISIONING, 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.

  1. Zitadel: deactivate org (blocks new logins; existing ID tokens remain valid until expiry).
  2. go-meet: control plane calls a signed POST /internal/admin/suspend → flush Redis sessions, deny new room tokens (broker also refuses to sign).
  3. Coolify: stop tenant stack (data volumes kept).

Resume reverses the order.

Offboarding and erasure

  1. Export (optional): tenant admin downloads recordings/transcripts (presigned), chat export via Matrix admin tooling.
  2. Stop stack, delete Coolify project (compose + volumes) (stop-stack).
  3. DROP DATABASE … WITH (FORCE) (terminates the sessions atomically) and DROP ROLE; decrement the shard’s tenant_count once (database).
  4. 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).
  5. 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).
  6. Zitadel: delete the meet app, deactivate and delete the org (users, apps, service accounts) (identity).
  7. Destroy the tenant backup key; older encrypted backups become unreadable (not in the prototype: no backups yet).
  8. Remove the room route and the DNS records (routes); the Coolify step (stop-stack) runs Pulumi destroy and then removes the stack, so the Coolify project, its containers and its volumes are gone and no state row is left in pulumi_state. In the prototype the step still uses the fake orchestrator (Pulumi not in the prototype yet).
  9. 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.

Was this page helpful?