Creating a tenant can involve database creation, migrations, initial roles and a welcome message. A single HTTP request cannot reliably guarantee that all external operations complete together.
Implementation approach
Persist provisioning status in the central database. Make each operation safe to retry and mark the tenant active only after mandatory setup steps succeed.
Example
type ProvisioningStatus =
'pending' | 'provisioning' | 'active' | 'failed';
Validation and edge cases
Simulate a migration failure after database creation and a worker crash before recording completion. Confirm retries resume from a safe checkpoint without creating duplicate databases or emails.
Key takeaway
Expose meaningful progress to administrators and retain a recovery procedure for partially provisioned tenants.




