Skip to main content

Architecture Overview

Graflow is a Python framework for distributed task execution and workflow management.

Design Philosophy

  1. Single Execution Engine: All execution paths use WorkflowEngine.execute(context, start_task_id)
  2. Peer-to-Peer Architecture: No Master/Slave relationships
  3. Transparent State Sharing: Channel-based abstraction for local/distributed
  4. Automatic Dependency Resolution: Graph-based successor processing

System Architecture

Core Components

ComponentRole
WorkflowEngineCentral execution engine with unified task execution loop
ExecutionContextState container: task queue, completed tasks, results, control flags
TaskGraphDAG structure holding task dependencies
TaskQueueAbstract queue (Memory / Redis implementations)
ChannelInter-task communication (Memory / Redis implementations)
TaskHandlerTask execution handler
GroupExecutorBSP-based parallel group execution

State Machine Execution

Tasks transition through three states:

PENDING → EXECUTING → COMPLETED
↑ │
└──── Queue successors ┘

Control Flow Priority

PriorityControlTask CompletedException
1cancel_workflow()NoYes
2terminate_workflow()YesNo
3goto (via next_task)YesNo
4Normal flowYesNo

Dynamic Flow Control

# Dynamic task generation
ctx.next_task(new_task) # Add task, process successors
ctx.next_task(new_task, goto=True) # Add task, skip successors
ctx.next_task(existing_task) # Jump to existing (auto-goto)

# Iteration
ctx.next_iteration(data) # Re-execute with data

# Workflow control
ctx.terminate_workflow("message") # Normal exit
ctx.cancel_workflow("message") # Abnormal exit

BSP Parallel Execution

ParallelGroup uses the BSP (Bulk Synchronous Parallel) model:

PhaseDescription
ComputationTasks execute in parallel
CommunicationResults shared via Channel
BarrierWait for all tasks to complete

Configuration

In-Memory (Local):

context = ExecutionContext.create(
graph=task_graph,
start_node="start",
channel_backend="memory"
)

Redis (Distributed): See Task Workers

Scalability & Reliability

AspectApproach
Horizontal scalingMultiple stateless workers via Redis
RetryConfigurable at TaskSpec level with exponential backoff
CheckpointsSave/restore execution state
Graceful shutdownSignal handling with active task completion

For distributed execution details, see Task Workers.