Understanding Workflow Execution
This document explains how Lemline executes workflows, from parsing the definition to completion.
Starting and observing an instance through the gateway
An application can submit a start request to the gRPC gateway. The gateway records the accepted request in its outbox in the orchestration database. The outbox publishes a command to the broker for a runner to execute.
As the instance runs, the runner emits lifecycle events. Lifecycle Analytics consumes them and stores the history that the gateway reads. Acceptance and visibility are separate moments: a successful StartInstance reply gives you the instance ID, and gateway history reads can return NOT_FOUND until the first lifecycle events reach analytics. The outbox preserves the accepted request while its command awaits delivery.
Follow a request from acceptance to completion in the gateway tutorial.
Execution Model Overview
Lemline implements a node-based execution model for Open Workflow DSL:
Parsing: The workflow definition (YAML/JSON) is parsed into a structured object model
Graph Construction: A directed graph of nodes is created from the model
State Management: Each node maintains its own execution state
Execution Flow: Nodes execute in sequence according to the workflow definition
Data Transformation: Data flows through the workflow, being transformed by expressions
Workflow Lifecycle
1. Initialization Phase
When a workflow definition is submitted to Lemline:
Parsing: The YAML/JSON is parsed into a data structure
Schema Validation: The structure is validated against the Open Workflow schema
Node Graph Construction: A directed graph of
NodeInstanceobjects is createdRegistration: The workflow is registered in the Lemline registry
2. Instantiation Phase
When a workflow instance is created:
Instance Creation: A new
WorkflowInstanceis createdInput Validation: Input data is validated against the input schema
Context Initialization: Initial data context is created with the input data
Execution Start: The execution begins with the root node
3. Execution Phase
During workflow execution:
Node Execution: The current node is executed
State Evaluation: The node's state is evaluated, and expressions are processed
Next Node Determination: The next node is determined based on the current state
Continuation: The process repeats until completion or suspension
4. Completion Phase
When workflow execution finishes:
Output Validation: Final data is validated against the output schema
Result Construction: The workflow result is constructed
State Update: The workflow state is updated to "completed"
Event Emission: Completion events are emitted
Node-Based Execution Model
Lemline's core execution model is based on a graph of nodes representing workflow tasks:
Node Structure
Each node in the workflow graph has:
Node Position
Node positions uniquely identify nodes within a workflow:
This hierarchical addressing enables:
Precise error reporting
State tracking at specific positions
Resume capability at exact positions
Node State
Each node maintains its own state:
Data Flow and Context Management
Data flows through the workflow in a structured way:
Hierarchical Scoping
Variables follow hierarchical scoping rules:
When resolving variables, Lemline searches:
The current node's scope
Parent scopes (up to the root)
Expression Evaluation
JQ expressions are evaluated against the current context:
The expression .orderTotal * .taxRate is evaluated with:
Current node's variables
Parent scope variables
Workflow input
Data Transformation Flow
As data moves through the workflow:
Each node:
Receives input data
Processes and transforms it
Outputs result to next node
Two-Phase Execution
Lemline implements a two-phase execution model:
Synchronous Execution Phase
Control flow nodes execute synchronously:
do- Sequential tasksswitch- Conditional branchingfor- Iterationsfork- Parallel executiontry- Error handlingset- Variable assignment
These nodes complete their execution immediately.
Asynchronous Execution Phase
Activity nodes may execute asynchronously:
callHTTP- External API callscallOpenAPI/callGRPC- Remote service callswait- Time-based waitinglisten- Event waitingrun- External process execution
These nodes can pause workflow execution, creating a "suspension point."
Suspension and Resumption
When a workflow encounters an asynchronous operation:
Suspension Process
Workflow execution reaches an asynchronous node
Current state is saved to the database
An outbox record is created for reliable processing
Execution suspends, waiting for completion event
Resumption Process
A completion event is received
Workflow state is loaded from the database
Async operation result is processed
Execution continues from the suspension point
Error Handling
Lemline provides robust error handling:
Error Types
Errors are categorized by type:
Configuration: Issues in the workflow definition
Validation: Schema validation failures
Expression: JQ expression evaluation errors
Runtime: Errors during workflow execution
Error Propagation
When an error occurs:
Error information is captured
Current
tryblock is checked for matchingcatchIf not caught, error propagates to parent
tryblocksIf never caught, workflow fails
Retry Mechanism
When error is caught and retry is configured:
Retry policy is evaluated
If retry is allowed, a wait period is calculated
After the wait, the
tryblock is re-executed
Performance Considerations
The Lemline execution model is designed for:
Efficiency
Minimal State: Only essential state is persisted
Lazy Evaluation: Expressions are evaluated only when needed
Targeted Persistence: State is persisted only at suspension points
Scalability
Stateless Execution: Between suspension points, execution is stateless
Horizontal Scaling: Multiple instances can process different workflows
Microservices Alignment: Fits naturally into microservices architecture
Reliability
Outbox Pattern: Ensures reliable message delivery
Atomic Operations: Database operations use transactions
Idempotent Processing: Events can be safely processed multiple times
Observability
The execution model provides comprehensive observability:
Tracing
Each workflow execution generates a trace with:
Node transitions
Expression evaluations
State changes
Error occurrences
Metrics
Key metrics include:
Execution time per node
Wait time at suspension points
Error rates
Retry counts
Logging
Structured logging captures:
Execution events
Data transformations
Error details
External interactions
Run the Examples
Every example on this page is a complete workflow. Complete the SQLite setup, save each example under the file name used below, and run the commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline.
Keep the setup worker running and use a second terminal in the setup directory.
Example | Expected result |
|---|---|
|
|