Skip to main content

Workflows Service

The Workflows Service is a visual workflow engine for orchestrating business processes, automations, and multi-step operations.

Overview

The Workflows Service enables you to:

  • Design workflows visually with nodes and edges
  • Execute multi-step business processes
  • Integrate with Functions, HTTP APIs, and external services
  • Schedule workflows with cron triggers
  • React to events with webhook triggers
  • Track execution history and debug failures

Architecture

┌─────────────────────────────────────────────────────────────┐
│ Workflows Service │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Define │───▶│ Publish │───▶│ Execute │ │
│ │ Workflow │ │ Workflow │ │ Workflow │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ Nodes │ │ Execution │ │
│ │ & Edges │ │ Engine │ │
│ └─────────────┘ └─────────────┘ │
│ │ │
│ ┌────────────────────┼──────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────┐ ┌──────────┐ ┌────┐ │
│ │ Functions│ │ HTTP │ │More│ │
│ │ Service │ │ APIs │ │... │ │
│ └──────────┘ └──────────┘ └────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│PostgreSQL│ │ RabbitMQ │ │ Quartz │
│ Database │ │ Events │ │Scheduler │
└──────────┘ └──────────┘ └──────────┘

Core Concepts

Workflows

A workflow is a directed graph of operations. Each workflow has:

PropertyDescription
NameDisplay name for the workflow
DescriptionWhat the workflow does
Application IDParent application reference
StatusDRAFT, ACTIVE, or PAUSED
VersionWorkflow version string
VariablesWorkflow-level variable schema

Nodes

Nodes represent individual steps in a workflow:

Node TypeDescription
STARTEntry point of the workflow
ENDExit point of the workflow
FUNCTIONInvoke a Nuraly function
HTTPMake HTTP requests to external APIs
CONDITIONConditional branching based on expressions
DELAYWait for a specified duration
TRANSFORMTransform data between nodes
VARIABLESet or get workflow variables
SUB_WORKFLOWExecute another workflow

Edges

Edges connect nodes and define the flow:

PropertyDescription
Source NodeWhere the edge starts
Target NodeWhere the edge ends
ConditionOptional condition expression
LabelDisplay label for the edge
PriorityOrder when multiple edges exist

Triggers

Triggers start workflow executions:

Trigger TypeDescription
WEBHOOKHTTP endpoint that triggers execution
SCHEDULECron-based scheduled execution
EVENTReact to external events

Executions

Each workflow run creates an execution record:

PropertyDescription
StatusPENDING, RUNNING, COMPLETED, FAILED, CANCELLED
InputInitial input data
OutputFinal output data
Started AtWhen execution began
Completed AtWhen execution finished
ErrorError message if failed

API Endpoints

Workflow Management

MethodEndpointDescription
GET/api/v1/workflowsList all workflows
GET/api/v1/workflows/{id}Get a specific workflow
POST/api/v1/workflowsCreate a new workflow
PUT/api/v1/workflows/{id}Update a workflow
DELETE/api/v1/workflows/{id}Delete a workflow

Workflow Operations

MethodEndpointDescription
POST/api/v1/workflows/{id}/publishPublish (activate) workflow
POST/api/v1/workflows/{id}/pausePause workflow
POST/api/v1/workflows/{id}/cloneClone workflow
POST/api/v1/workflows/{id}/validateValidate workflow

Execution

MethodEndpointDescription
POST/api/v1/workflows/{id}/executeExecute workflow
GET/api/v1/workflows/{id}/executionsList executions
GET/api/v1/executions/{id}Get execution details
POST/api/v1/executions/{id}/cancelCancel execution
POST/api/v1/executions/{id}/retryRetry failed execution

Node & Edge Management

MethodEndpointDescription
GET/api/v1/workflows/{id}/nodesGet workflow nodes
POST/api/v1/workflows/{id}/nodesAdd a node
PUT/api/v1/nodes/{id}Update a node
DELETE/api/v1/nodes/{id}Delete a node
GET/api/v1/workflows/{id}/edgesGet workflow edges
POST/api/v1/workflows/{id}/edgesAdd an edge
DELETE/api/v1/edges/{id}Delete an edge

Triggers

MethodEndpointDescription
GET/api/v1/workflows/{id}/triggersList triggers
POST/api/v1/workflows/{id}/triggersCreate trigger
DELETE/api/v1/triggers/{id}Delete trigger
POST/api/v1/webhooks/{token}Webhook endpoint

How It Works

Creating a Workflow

POST /api/v1/workflows
{
"name": "Order Processing",
"description": "Process new orders",
"applicationId": "app-123"
}

Adding Nodes

POST /api/v1/workflows/{id}/nodes
{
"name": "Validate Order",
"type": "FUNCTION",
"configuration": {
"functionId": "uuid-of-validation-function"
},
"positionX": 200,
"positionY": 100
}

Connecting Nodes with Edges

POST /api/v1/workflows/{id}/edges
{
"sourceNodeId": "start-node-uuid",
"targetNodeId": "validate-node-uuid",
"label": "Start"
}

Publishing a Workflow

POST /api/v1/workflows/{id}/publish

The workflow is validated before publishing:

  • Must have a START node
  • Must have at least one END node
  • All nodes must be connected
  • Node configurations must be valid

Executing a Workflow

POST /api/v1/workflows/{id}/execute
{
"input": {
"orderId": "order-123",
"items": [{"sku": "ABC", "qty": 2}]
}
}

Response:

{
"executionId": "exec-uuid",
"status": "RUNNING",
"startedAt": "2024-01-15T10:00:00Z"
}

Using Conditions

CONDITION nodes evaluate JavaScript expressions:

{
"type": "CONDITION",
"configuration": {
"expression": "input.total > 100"
}
}

Edges from condition nodes use condition for routing:

  • true - Expression evaluated to true
  • false - Expression evaluated to false

Setting Up Webhooks

POST /api/v1/workflows/{id}/triggers
{
"type": "WEBHOOK",
"name": "Order Webhook"
}

Response includes the webhook URL:

{
"id": "trigger-uuid",
"type": "WEBHOOK",
"webhookToken": "abc123",
"webhookUrl": "http://localhost:7002/api/v1/webhooks/abc123"
}

Scheduling Workflows

POST /api/v1/workflows/{id}/triggers
{
"type": "SCHEDULE",
"name": "Daily Report",
"configuration": {
"cronExpression": "0 0 9 * * ?"
}
}

Integration Points

ServicePurpose
PostgreSQLStores workflows, executions, and history
FunctionsExecutes serverless functions in FUNCTION nodes
RabbitMQPublishes workflow events
QuartzManages scheduled triggers
API ServiceValidates permissions
GatewayRoutes external requests
KV ServiceRetrieves secrets and configuration

Execution States

StatusDescription
PENDINGExecution queued
RUNNINGCurrently executing
COMPLETEDFinished successfully
FAILEDExecution failed
CANCELLEDManually cancelled
WAITINGWaiting (e.g., DELAY node)

Best Practices

Workflow Design

  • Keep workflows focused on a single process
  • Use descriptive names for nodes
  • Add error handling paths
  • Use TRANSFORM nodes to prepare data

Error Handling

  • Add conditional branches for error cases
  • Configure retries for transient failures
  • Log important data with VARIABLE nodes
  • Use END nodes with error status

Performance

  • Avoid long-running synchronous operations
  • Use DELAY nodes instead of polling
  • Keep node count reasonable
  • Monitor execution times

Testing

  • Test workflows in DRAFT status first
  • Use the validate endpoint before publishing
  • Check execution history for failures

API Documentation

Interactive API documentation is available at:

/api/v1/workflows/swagger-ui

Next Steps