Backend Development 8 min read

Introducing Liteflow: A Lightweight Java Rule Engine for Complex Workflow Orchestration

This article presents Liteflow, a lightweight yet powerful Java rule engine that supports XML/JSON/YAML rule files, multiple storage backends, and hot‑deployment, and demonstrates its components, configuration, and a real‑world e‑commerce workflow example with code snippets.

Architect's Guide
Architect's Guide
Architect's Guide
Introducing Liteflow: A Lightweight Java Rule Engine for Complex Workflow Orchestration

In daily development, serial and parallel business processes often lack correlation, and using strategy and template patterns can become cumbersome; this article introduces Liteflow, a lightweight yet powerful rule engine that addresses such scenarios from a global perspective.

Liteflow supports multiple rule file formats (XML, JSON, YAML) and storage options (SQL, Zookeeper, Nacos, Apollo). Its architecture enables rapid composition of complex rule orchestrations, as illustrated in the diagram.

The engine operates by obtaining a data context, parsing rule files, and executing chains composed of nodes that can run scripts in various languages (Groovy, JS, Python, Lua). Nodes are defined as components such as ordinary components, switch components, and conditional components.

Ordinary components extend NodeComponent , providing process logic and lifecycle hooks like isContinueOnError and isEnd . Switch components inherit NodeSwitchComponent and implement processSwitch to select the next node. Conditional components extend NodeIfComponent and override processIf to return a boolean.

# flow rule expression for switch component
SWITCH(a).to(b, c);
# processSwitch expression must return "b" or "c"
# flow rule expression for condition component
IF(x, a, b);

Rule files are typically written in EL XML, supporting serial ( THEN ), parallel ( WHEN ), switch, and conditional compositions, with nesting capabilities.

# file orchestration, THEN for serial, WHEN for parallel
THEN(a, b, c, d);
WHEN(a, b, c);
THEN( a, WHEN(b, c, d), e);
SWITCH(a).to(b, c, d);
THEN(IF(x, a), b );

Configuration parameters in liteflow include rule source paths, retry counts, thread pool settings, request ID generator, slot size, and hot‑deployment options, allowing real‑time updates of rule files.

liteflow:
  ruleSource: liteflow/*.el.xml
  retry-count: 0
  print-execution-log: true
  monitor:
    enable-log: true
    period: 300000
  request-id-generator-class: com.platform.orderserver.config.AppRequestIdGenerator
  slot-size: 10240
  main-executor-works: 64
  when-max-wait-seconds: 15
  when-max-workers: 16
  when-queue-limit: 5120
  parse-on-start: true
  enable: true

A practical e‑commerce scenario demonstrates using Liteflow to grant points, send messages, and concurrently dispatch SMS and email after an order completes. The flow is defined in an XML chain and executed with flowExecutor.execute2Resp , passing initial parameters and a custom context class.

<flow>
    <chain name="test_flow">
        THEN(
            prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
        );
    </chain>
</flow>

Overall, Liteflow performs most initialization at startup—parsing rules, registering components, and assembling metadata—yielding high execution performance while providing detailed timing and statistics. The article concludes with a link to the GitHub repository for further exploration.

BackendJavarule engineworkflowSpring BootELLiteFlow
Architect's Guide
Written by

Architect's Guide

Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.