๐Ÿ“˜ Temporal Workflow Concepts

Understanding Core Identifiers

Key identifiers in a Temporal workflow: workflowType, workflowId, runId, and taskQueue


๐Ÿ”‘ Key Fields Explained

Field Description
workflowType The name of the workflow class or function (defined in code)
workflowId The unique identifier for a workflow execution. Used to ensure idempotency
runId A unique ID for a specific run of the workflow. Changes on retries/restarts
taskQueue The name of the queue where the workflow or activity is polled and processed

๐Ÿงน Code Example

val options = WorkflowOptions.newBuilder()
    .setTaskQueue("order-processing-queue")
    .setWorkflowId("order-12345")
    .build()

val workflow = client.newWorkflowStub(OrderWorkflow::class.java, options)
WorkflowClient.start(workflow::placeOrder)

In this example:

  • workflowType: OrderWorkflow (inferred from the stub)
  • workflowId: order-12345
  • taskQueue: "order-processing-queue"
  • runId: Generated at runtime

๐Ÿ” workflowId vs runId

Property workflowId runId
Scope Logical workflow Specific execution/run
Changes? โŒ Never โœ… Yes (new ID on retry or restart)
Use Case Query, signal, deduplication History inspection, debugging

Key Distinction:

  • workflowId โ†’ Business identity (same across retries)
  • runId โ†’ Execution identity (unique per attempt)

๐Ÿ› Workflow Lifecycle Diagram

sequenceDiagram participant Client participant TemporalServer participant Worker Client->>TemporalServer: StartWorkflow (workflowId: "order-12345") activate TemporalServer TemporalServer-->>Client: runId: "run-xyz" TemporalServer->>Worker: Poll task (taskQueue: "order-processing-queue") Worker-->>TemporalServer: Complete Activity deactivate TemporalServer

Shows how identifiers flow through the Temporal system


๐ŸŒŸ Usage Summary

workflowType

  • Defined in code: class/interface (e.g., OrderWorkflow)
  • Used for routing to the correct workflow implementation

workflowId

  • Application-controlled identifier
  • Enables deduplication, signals, queries

runId

  • Server-generated identifier
  • Used to debug specific workflow runs

taskQueue

  • Decouples workflow definition from execution
  • Enables horizontal scaling of workers

๐Ÿ” CLI Usage

# Show workflow by workflow ID
tctl workflow show --workflow-id order-12345

# Show specific run of workflow
tctl workflow show --workflow-id order-12345 --run-id abcdef123456

Production Operations:

  • Query workflows by business ID (workflowId)
  • Debug specific executions using runId
  • Monitor task queues for scaling decisions

โœ… Best Practices

Workflow ID Guidelines:

  • โœ… Use UUIDs or meaningful domain IDs for workflowId
  • โœ… Include business context (e.g., order-12345, user-onboarding-abc)
  • โœ… Avoid random values for better traceability

Task Queue Guidelines:

  • โœ… Keep names environment-specific (e.g., "email-prod" vs "email-dev")
  • โœ… Use descriptive names ("order-processing" not "queue1")
  • โœ… Separate by function (different queues for different workflow types)

General Guidelines:

  • โœ… Avoid randomness inside workflows (ensure determinism)
  • โœ… Use meaningful identifiers for easier debugging

๐Ÿ’ก Key Takeaways

What You've Learned:

  • โœ… Workflow identifiers serve different purposes in the system
  • โœ… workflowId provides business identity and deduplication
  • โœ… runId enables debugging specific executions
  • โœ… taskQueue enables scaling and deployment flexibility
  • โœ… Best practices ensure maintainable and debuggable workflows

๐Ÿš€ Production Impact

Understanding these identifiers enables:

  • โœ… Effective monitoring and alerting
  • โœ… Efficient debugging of production issues
  • โœ… Proper scaling strategies
  • โœ… Clean deployment patterns
  • โœ… Business traceability across systems

Essential knowledge for production Temporal systems! ๐ŸŽ‰

results matching ""

    No results matching ""