A tenant’s lifecycle
This page explains, for technical readers, a tenant’s life in subscription, from its creation to its purge, and what each service does about it. The screens are described in Clients and tenants and Purge.
Statuses
A tenant (Tenant, table tenant) has a status, TenantStatus:
| Status | Meaning | Access |
|---|---|---|
ACTIVE |
The normal status. | Yes, inside the validity window. |
SUSPENDED |
Suspended by a platform administrator: everything is kept. | No, until reactivated. |
PENDING_DELETION |
Deletion requested: everything is kept, the tenant can be restored until its purge date. | No. |
DELETED |
Purged: members removed; the row and the login credential are kept, the name and id stay reserved. Final. | No. |
The transitions:
| From | Action | To | Endpoint |
|---|---|---|---|
ACTIVE |
Suspend | SUSPENDED |
PUT /api/v1/tenants/{id}/suspension |
SUSPENDED |
Reactivate | ACTIVE |
DELETE /api/v1/tenants/{id}/suspension |
ACTIVE, SUSPENDED |
Schedule deletion | PENDING_DELETION |
DELETE /api/v1/tenants/{id} (202) |
PENDING_DELETION |
Restore | SUSPENDED if it was before, else ACTIVE |
POST /api/v1/tenants/{id}/restore |
PENDING_DELETION |
Purge, once the date has passed | DELETED |
TenantPurgeJob |
The server answers 409 to an action the status does not allow: suspending or reactivating a PENDING_DELETION tenant (error.tenant.pendingDeletion), restoring a tenant that is not PENDING_DELETION (error.tenant.notPendingDeletion), changing anything about a DELETED tenant (error.tenant.deleted). Suspending a suspended tenant, reactivating an active one, or scheduling the deletion of a tenant already pending changes nothing; in the last case, it keeps its purge date.
The suspension time (suspendedSince) survives a deletion request: it is what lets a restore give back SUSPENDED.
Validity
Whatever its status, a tenant has a validity window, validFrom (included) and validUntil (excluded). An empty bound is no limit. PUT /api/v1/tenants/{id}/validity replaces the whole window; an end that does not come after the start is refused (400). The validity can be changed in any status but DELETED.
The status stays ACTIVE when the window is over or not started: it is the access lookup that compares the present moment with the window, at every read. Nothing therefore happens at the moment a contract ends, except that no access is found any more.
The last day of access is the Paris-time day of the instant just before validUntil. A validUntil on 1 January at 00:00 therefore gives 31 December as the last day.
What gives access to a tenant
The services ask subscription for a user’s accesses (see The services’ membership lookups). An access is returned only if, at the time of the read:
- the tenant is
ACTIVE; - the moment is inside its validity window;
- the user’s access to that tenant is not suspended;
- the user is not disabled.
Giving or changing an access is allowed only in an ACTIVE tenant (409 error.tenant.inactive otherwise); removing an access stays allowed in any status. The validity window is not looked at: an access can be prepared before the contract starts.
Creation
POST /api/v1/tenants creates the tenant:
- with a random public id,
tenantId: the Reference of the screens, the one the services store, distinct from subscription’s primary key; - with a unique name,
DELETEDtenants included; - attached to a client, required;
ACTIVE, with no validity window;- with its login credential (
TenantCredential).
The login credential is a password, the tenant’s encryption secret. The only type accepted is PASSWORD: KEY is refused (400), as no service encrypts with a key pair yet. The password may be neither empty nor shorter than application.credential.minimum-password-length. subscription adds a random salt to it. The password and the salt are encrypted in the database with the current master key; a restart re-encrypts with the current key the values left on an old one (TenantCredentialReencryption).
GET /api/v1/security/password/generate provides the generated password the form offers. No screen reads the credential back: only GET /api/v1/tenant-credentials?tenantId= serves it, to the services of the tenant-credentials group (irrc) and to them alone, never to a user’s token, administrators included. Each read is logged with the caller and the tenant, never the secret. It stays readable after the purge.
Suspension and reactivation
Suspension cuts the access of all the tenant’s users and removes nothing. Reactivation gives it back. Both tell irrc (see UPDATE_PLAN messages) and mail the members (see Mails to members).
Deletion and waiting period
Scheduling the deletion puts the tenant in PENDING_DELETION, whether it has members or not:
deletionRequestedAtgets the moment of the request;deletionScheduledAtgets the purge date: the request plus the waiting period,application.tenant-lifecycle.deletion-grace-period, 60 days by default.
During that period no access is found, everything is kept, and Restore gives the tenant back its former status. The restore clears both dates.
The screens say “60 days” as a fixed value, in the confirmation and in the computation of the restore date. If the waiting period is configured otherwise, the date in the confirmation will be wrong; the actual date is the one the tag and the tenant’s page show afterwards, read from the server.
The purge
TenantPurgeJob runs every 15 minutes (application.tenant-lifecycle.purge-cron). It purges the tenants that are due: PENDING_DELETION past their purge date, or test tenants past their lifetime (see Test tenants).
Each tenant is purged in its own transaction, under a FOR UPDATE SKIP LOCKED row lock: of several replicas, only one purges a given tenant, and a tenant restored meanwhile is skipped. The purge:
- deletes all the tenant’s accesses (
user_tenant) and its members (tenant_member); - records every right removed in the access history, with the cause “because the tenant was purged” (
TENANT_PURGED); - sets the tenant to
DELETEDwithdeletedAt; - sends
UPDATE_PLANto irrc; - sends
TENANT_DELETEDontenant_lifecycle_topic.
Each send waits for the broker’s acknowledgement. A failed send rolls the tenant’s whole purge back, to be tried again on the next run. The purge mails nobody: the members were told when the deletion was scheduled.
The DELETED tenant keeps its row and its login credential; its name and its tenantId stay reserved.
The TENANT_DELETED event
TENANT_DELETED is published on tenant_lifecycle_topic, keyed by tenantId so that one tenant’s messages stay in order:
{ "tenantId": "12359bb8-b120-11ed-afa1-0242ac120005", "messageType": "TENANT_DELETED",
"deletedAt": "2026-11-04T03:30:00.123456Z", "schemaVersion": 1 }tenantIdis the tenant’s public id, never subscription’s primary key.- The message is sent once, when the purge commits, but delivered at least once: a consumer must be idempotent.
- A consumer ignores a
messageTypeit does not know. - The message is sent before the purge transaction commits: for a few milliseconds, a service reading the status may still see the tenant not
DELETED.
A service can check a tenant’s status by its public id with GET /api/v1/tenant-status?tenantId=, reserved to the services of the tenant-status group and platform administrators. The answer gives status, deletedAt and purgeDue (the tenant would be purged now). An unknown tenantId answers 404: the tenant never existed, or it was a test tenant erased after its purge.
What each service purges
| Service | What it deletes on TENANT_DELETED |
Specifics |
|---|---|---|
| irrc (MyReg) | The tenant’s objects in S3, then the rows of every table with a tenant_id column (read from the catalog, children first), then what the replica’s caches hold of it. |
One transaction for the rows. A single replica purges; a failure is retried, then put in tenant_lifecycle_topic.DLT. No tenant is exempt. |
| library | The tenant’s own documents and their files, tasks, summaries, docling conversion markers, its passages in the index, and its users. The common library and the other tenants are untouched. | In batches, each committed on its own. A failure is retried, then tenant_lifecycle_topic.DLT. |
| ALM (stress, risk-app) | Every row and object of the tenant; each replica also drops its local caches of the tenant. | Purges only after checking with subscription that the tenant is DELETED (GET /api/v1/tenant-status). Never purges its default tenant. Active only when ALM runs with subscription. |
Each service purges idempotently: a replayed message finds nothing left. The Purge page asks these three services whether they still hold anything of a deleted tenant, and erases the data of tenants subscription does not know.
UPDATE_PLAN messages
Every status or validity change, like every access change, sends irrc an UPDATE_PLAN message on subscription_irrc_topic, keyed by tenantId. irrc then clears its cache of that tenant’s accesses and reads them again from subscription.
The change is written, then the message is sent in the same transaction and its acknowledgement awaited: a failed send rolls the change back and fails the request. A revocation is therefore never committed without irrc being told. An unchanged validity sends nothing.
Mails to members
A tenant’s members (a role or a plan, and an e-mail address) get a mail when its status changes:
| Event | |
|---|---|
| Suspension | Access stops. |
| Deletion scheduled | No access; data purged on the purge date unless restored. |
Reactivation, or restore to ACTIVE |
Access is back. A member whose own access is suspended gets none. |
Restore to SUSPENDED |
The deletion is cancelled; access stays suspended. |
A validity change and the purge mail nobody. Each mail is in the user’s language, or in French then English when they chose none. The mails leave after the change commits, through the notification service (SEND_MAIL on notification_topic): a rolled-back change mails nobody, and a failed send is logged without undoing the change.
End-of-contract reminders
ContractReminderJob runs every day at 08:00, Paris time (application.contract-reminders.cron). It looks only at ACTIVE tenants with a validUntil: an open-ended tenant is never reminded about.
| Recipient | Default thresholds | Setting |
|---|---|---|
MLA (support.reglab@mladvisory.eu by default), a single mail to all its addresses, in its language (fr by default) |
60, 30 and 7 days before the last day | mla-recipients, mla-language, mla-thresholds-days |
| The tenant’s admins: admin role, access not suspended, account not disabled, an e-mail address. Each in their language, or in French then English. | 30 and 7 days | admin-thresholds-days |
| Both | End of contract (“ended”), up to 7 days after | ended-lookback |
A threshold of N days is due from the day N days are left before the last day of access. Of the thresholds due and not handled yet, only the most urgent is sent; the others are recorded as skipped. A late run, or a validity set close to its end, therefore sends a single mail. A contract ended more than 7 days ago is no longer mailed about, so that the first run does not mail about contracts that ended long ago.
Each reminder sent or skipped is recorded (contract_reminder: tenant, validUntil, threshold, date, number of recipients) and never sent again for the same validUntil. Extending a tenant changes its validUntil: the reminders start again for the new date, and the old ones stay visible under Earlier end dates. Each tenant is handled in its own transaction, under a FOR UPDATE SKIP LOCKED lock; a failed mail rolls back the tenant’s records, tried again the next day.
The Contracts ending soon panel reads GET /api/v1/tenants/contract-endings?days=60 (the ACTIVE tenants whose end falls within 60 days or passed less than 30 days ago); a tenant’s Contract card reads GET /api/v1/tenants/{id}/contract-reminders.
Test tenants
The end-to-end tests create and delete their own tenants through the API. A tenant whose name contains playwright (application.tenant-lifecycle.test-tenant-marker, ignoring case) is a test tenant, and may get:
- on creation, a lifetime,
expiresAfter(an ISO-8601 duration such asPT1H): the purge purges it when it runs out, with no deletion request. Such a tenant is called temporary; - on deletion, a notice period shorter than the waiting period,
noticePeriod.
These durations lie between minimum-notice-period (1 hour) and the waiting period; any other tenant asking for one is refused (400).
A temporary tenant leaves no trace: its access changes are neither recorded in the history nor mailed. Two days after its purge (temporary-tenant-retention), the purge erases it entirely, row and login credential included. A service receiving its TENANT_DELETED later no longer finds it (404); whatever data it may still hold then becomes orphan data, erasable from the Purge page.
Settings
| Property | Default | Role |
|---|---|---|
application.tenant-lifecycle.deletion-grace-period |
60 days | Waiting period before the purge. |
application.tenant-lifecycle.purge-cron |
every 15 minutes | The purge’s runs; - disables it. |
application.tenant-lifecycle.minimum-notice-period |
1 hour | A test tenant’s shortest notice period. |
application.tenant-lifecycle.test-tenant-marker |
playwright |
What marks a test tenant in its name. |
application.tenant-lifecycle.temporary-tenant-retention |
2 days | Delay before a purged temporary tenant is erased. |
application.contract-reminders.* |
see above | End-of-contract reminders. |
application.kafka.send-timeout |
10 seconds | Longest wait for a Kafka send’s acknowledgement. |