Backend Development 11 min read

Introducing LiteFlow: A Lightweight Rule Engine for Java Backend Development

This article introduces LiteFlow, a lightweight yet powerful Java rule engine, explains its architecture, component types, EL rule file syntax, configuration options, and demonstrates a real‑world e‑commerce workflow example, providing code snippets and deployment tips for backend developers.

Top Architect
Top Architect
Top Architect
Introducing LiteFlow: A Lightweight Rule Engine for Java Backend Development

In modern backend development, handling serial and parallel business processes can become cumbersome; LiteFlow offers a lightweight, powerful rule engine that enables clear, global orchestration of such workflows.

The engine’s overall architecture (see the diagram in the original article) supports multiple rule file formats (XML, JSON, YAML) and storage back‑ends such as SQL, Zookeeper, Nacos, or Apollo.

LiteFlow defines three main component types:

Ordinary components, implemented by extending NodeComponent , where business logic resides in the process method.

Switch components, extending NodeSwitchComponent , which decide the next node based on a custom processSwitch implementation (similar to a Java switch ).

Condition components, extending NodeIfComponent , returning a boolean via processIf to control flow.

Rule files are typically written in EL XML. A simple example shows serial ( THEN ) and parallel ( WHEN ) composition, as well as nested and conditional structures:

# flow 规则表达式 选择组件
SWITCH(a).to(b, c);
# processSwitch 表达式需要返回的是 b 或者 c 字符串来执行相应的业务逻辑
# flow 规则表达式 条件组件
IF(x, a, b);

The Maven dependency required to use LiteFlow in a Spring Boot project is:

<dependency>
    <groupId>com.yomahub</groupId>
    <artifactId>liteflow-spring-boot-starter</artifactId>
    <version>2.10.6</version>
</dependency>

Configuration is done via a YAML block, controlling rule source location, retry count, logging, monitoring, request‑ID generation, thread pool sizes, and hot‑deployment options:

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 is presented, where after an order is completed the system grants points, sends messages, and concurrently sends SMS and email. The flow is defined in an XML file:

<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <chain name="test_flow">
        THEN(
            prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
        );
    </chain>
</flow>

During execution, a data context object carries parameters between nodes, allowing each node to access or modify the shared state. The engine parses rules at startup, registers components, and assembles the execution graph, resulting in high performance while offering detailed timing and statistics.

Overall, LiteFlow provides a concise, high‑performance solution for rule‑driven workflow orchestration in Java backend systems, with extensible components, hot‑deployment, and comprehensive configuration.

Javarule enginebackend developmentSpring BootLiteFlow
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

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.