Workflow Service
The Workflow Service orchestrates complex, multi-step business processes and state transitions using a reliable event-driven engine. It ensures that long-running transactions are handled correctly, even in the face of transient failures.
Overview
Citadel uses Temporal as the underlying engine for the Workflow Service. This allows us to write "durable code" that can run for days or weeks, handling retries and state management automatically.
The service primarily follows the Orchestration-based Saga pattern for distributed transactions.
Key Features
- Reliable Step Execution: Ensures every step of a process (e.g., Tenant Provisioning) completes or is compensated.
- Saga Compensation: If a critical step fails, the service automatically triggers rollback activities to maintain system consistency.
- Signal & Query: Interact with running workflows (e.g., send an "Approval" signal).
- Temporal Integration: Benefit from Temporal's observability, scalability, and reliability.
Common Workflows
Tenant Onboarding
The most common workflow in Citadel is the TenantOnboardingWorkflow. It coordinates:
- Approval: Waiting for an administrator to approve the signup.
- Provisioning: Creating the tenant record in the database.
- IAM Interaction: Assigning the initial administrator role to the user.
- Notifications: Sending a welcome email.
Working with Workflows
Workflows are defined in Go using the Temporal SDK.
Starting a Workflow
You can trigger a workflow via the REST API or directly using the Temporal client.
API Example:
POST /v1/workflows/onboarding
Monitoring Workflows
Use the Temporal UI (available at http://localhost:8233 in development) to visualize workflow progress, inspect step history, and debug failures.