Generated SaaS Workflows¶
Target Architecture — Final-State Design
This page describes the common runtime workflows of a Generated SaaS Product, centered on tenant provisioning and onboarding. Workflows are coordinated as MassTransit sagas/state machines over the canonical event envelope, with each step idempotent and compensatable. Products add domain-specific workflows; the onboarding flow below is universal.
The most important generated workflow is tenant onboarding — turning a sign-up into a fully provisioned, billable, ready-to-use tenant. It exercises the SaaS spine end to end: tenancy, identity, subscriptions, configuration, notifications, and audit. The flow is orchestrated, observable by traceId, and resilient to partial failure through compensation.
Tenant provisioning & onboarding sequence¶
sequenceDiagram
participant Admin as Signup / Admin Portal
participant GW as API Gateway
participant Tenant as Tenant Management
participant Bus as Service Bus
participant Sub as Subscription & Billing
participant Identity as Identity Service
participant Config as Configuration Service
participant Notif as Notification Service
participant Audit as Audit Trail
Admin->>GW: POST /tenants (RegisterTenant)
GW->>Tenant: RegisterTenant (tenant-scoped)
Tenant->>Tenant: create Tenant (Provisioning)
Tenant->>Bus: TenantRegistered
Bus->>Audit: AuditEntryRecorded
Bus->>Sub: TenantRegistered
Sub->>Sub: create Subscription (Trial/Active)
Sub->>Bus: SubscriptionActivated
Bus->>Config: SubscriptionActivated
Config->>Config: apply edition entitlements + default flags
Bus->>Identity: TenantRegistered
Identity->>Identity: create owner User (Invited)
Identity->>Bus: UserInvited
Bus->>Notif: UserInvited
Notif->>Notif: send activation email
Notif->>Bus: NotificationSent
Sub-->>Tenant: provisioning step complete
Config-->>Tenant: provisioning step complete
Identity-->>Tenant: provisioning step complete
Tenant->>Tenant: all steps complete -> Active
Tenant->>Bus: TenantProvisioned
Bus->>Audit: AuditEntryRecorded
Tenant onboarding state machine¶
stateDiagram-v2
[*] --> Registered
Registered --> Provisioning : begin provisioning steps
Provisioning --> Provisioning : step completed
Provisioning --> Active : all steps succeeded
Provisioning --> ProvisioningFailed : a step failed
ProvisioningFailed --> Provisioning : retry after remediation
ProvisioningFailed --> Decommissioned : abandon + compensate
Active --> Suspended : payment past due / policy
Suspended --> Active : reinstated
Active --> Decommissioned : tenant closed
Suspended --> Decommissioned : tenant closed
Decommissioned --> [*]
Failure handling¶
- Saga orchestration. Tenant provisioning is a MassTransit saga: the
Tenantaggregate tracksProvisioningSteps, and the saga only transitions toActiveonce every step publishes success. - Idempotency. Each step consumer deduplicates on
eventId, so redelivery never double-provisions (e.g. a secondSubscriptionActivatedis ignored). - Compensation. If a step fails irrecoverably, the saga issues compensating actions (e.g. cancel the half-created subscription, disable the invited user) and moves the tenant to
ProvisioningFailed. - Bounded retry + DLQ. Transient failures retry with backoff; exhausted messages dead-letter with the full envelope for operator replay.
- Timeouts. A provisioning timeout transitions the saga to
ProvisioningFailedand emits aTenantProvisioningTimedOutevent for alerting. - Audit on every transition. Each state change emits
AuditEntryRecorded, so the onboarding history is reconstructable and compliant.
Implementation Notes
Because all steps are enveloped events correlated by correlationId, the entire onboarding flow for a given tenant can be visualized end to end in the product's observability dashboards and traced back through the factory's Observability & Feedback platform.
How workflows contribute to the pillars¶
- Traceability —
correlationIdties every step of onboarding into one reconstructable flow;causationIdbuilds the causal chain. - Reusability — the onboarding saga is generated from the same template across products; only domain steps differ.
- Autonomy — the saga and its compensations are generated from the blueprint workflow definition.
- Governance — every transition is audited; suspension and decommission encode policy.
- Observability — saga state and step durations are emitted as metrics and traces.
- Multi-tenant scale — each tenant's onboarding is an isolated saga instance; thousands run concurrently without interference.