Skip to content

Latest commit

 

History

History
157 lines (127 loc) · 5.62 KB

ARCHITECTURE.md

File metadata and controls

157 lines (127 loc) · 5.62 KB

High-level view

At the highest level, the components of a system using Temporal fall into two categories:

  • User-hosted processes

    • The user's application communicates with the Temporal server using one of the Temporal SDKs.
    • The user runs Temporal Worker processes. These also use one of the Temporal SDKs and host the user's Workflow and Activity code.
  • Temporal Server
    Users can host and operate the Temporal server and its database themselves, or use Temporal Cloud.

image

Workflow lifecycle

Below we follow a typical sequence of events in the execution of the following very simple workflow:

myWorkflow() {
   result = callActivity(myActivity)
   return result
}

1. The User Application uses a Temporal SDK to send a StartWorkflowExecution request to the Frontend service.

sequenceDiagram
User Application->>Frontend: StartWorkflowExecution
Frontend->> History: StartWorkflowExecution
History ->> Persistence: CreateWorkflowExecution
Persistence ->> Persistence: Persist MutableState and history tasks
Persistence ->> History: Create Succeed
History->>Frontend: Start Succeed
Frontend->>User Application: Start Succeed
loop QueueProcessor
    History->>Persistence: GetHistoryTasks
		History->>History: ProcessTask
		History->>Matching: AddWorkflowTask
end
  • The Frontend Service uses a History Service client to call the StartWorkflow handler.
  • This initializes history events with a WorkflowExecutionStarted event, and persists new mutable state and a history task (transfer task).
  • A queue processor goroutine runs for every history task queue.
  • The transfer task queue processor adds a Workflow Task in the appropriate task queue in the Matching Service.

2. The Worker dequeues the Workflow Task, advances the workflow execution, and becomes blocked on the Activity call.

sequenceDiagram
Worker->>Frontend: PollWorkflowTask
Frontend->>Matching: PollWorkflowTask
History->>Matching: AddWorkflowTask
Matching->>History: RecordWorkflowTaskStarted
History->>Persistence: UpdateWorkflowExecution
Persistence->>Persistence: Update MutableState & Add timeout timer
Persistence->>History: Update Succeed
History->>Matching: Record Succeed
Matching->>Frontend: WorkflowTask
Frontend->>Persistence: GetHistoryEvents
Persistence->>Frontend: History Events
Frontend->>Worker: WorkflowTask
loop Replayer
    Worker->>Worker: ProcessEvent
end

3. The Worker sends a ScheduleActivityTask; an Activity task is added in the Matching service.

sequenceDiagram
Worker ->> Frontend: RespondWorkflowTaskCompleted(ScheduleActivityTask)
Frontend->> History: RespondWorkflowTaskCompleted(ScheduleActivityTask)
History ->> Persistence: UpdateWorkflowExecution
Persistence ->> Persistence: Persist MutableState and history tasks
Persistence ->> History: Update Succeed
History->>Frontend: Respond Succeed
Frontend->>Worker: Respond Succeed
loop QueueProcessor
    History->>Persistence: GetHistoryTasks
		History->>History: ProcessTask
		History->>Matching: AddActivityTask
end

4. The Worker dequeues the Activity task

sequenceDiagram
title: Activity task start
Worker->>Frontend: PollActivityTask
Frontend->>Matching: PollActivityTask
History->>Matching: AddActivityTask
Matching->>History: RecordActivityStarted
History->>Persistence: UpdateWorkflowExecution
Persistence->>Persistence: Update MutableState, add timeout timer
Persistence->>History: Update succeed
History->>Matching: Record Succeed
Matching->>Frontend: ActivityTask
Frontend->>Worker: ActivityTask

4. The Worker sends RespondActivityCompleted to the History service; a Workflow Task is added to the Matching service

sequenceDiagram
SDK->>Frontend: RespondActivityCompleted
Frontend->>History: RespondActivityCompleted
History->>Persistence: UpdateWorkflowExecution
Persistence->>Persistence: Update MutableState & add transfer task
Persistence->>History: Update Succeed
History->>Frontend: Respond Succeed
Frontend->>SDK: Respond Succeed
loop QueueProcessor
    History->>Persistence: GetHistoryTasks
		History->>History: ProcessTask
		History->>Matching: AddWorkflowTask
end

5. The Worker dequeues the Workflow Task, advances the workflow, and finds that it has reached its end

<Same sequence diagram as step 2 above>


6. The Worker sends RespondWorkflowTaskCompleted to the History Service

sequenceDiagram
SDK->>Frontend: RespondWorkflowTaskCompleted
Frontend->>History: RespondWorkflowTaskCompleted
History->>Persistence: UpdateWorkflowExecution
Persistence->>Persistence: Update MutableState & add tasks (visibility, tiered storage, retention etc)
Persistence->>History: Update Succeed
History->>Frontend: Respond Succeed
Frontend->>SDK: Respond Succeed
loop QueueProcessor
    History->>Persistence: GetHistoryTasks
		History->>History: ProcessTask (Update visibility, Upload to S3, Delete data etc)
end