Master Liteflow: A Lightweight Rule Engine for Complex Business Flows

This article introduces the Liteflow rule engine, explains its architecture, component types, EL rule syntax, data context handling, Spring Boot configuration, and demonstrates a real‑world e‑commerce order processing scenario with code examples and diagrams.

Top Architect
Top Architect
Top Architect
Master Liteflow: A Lightweight Rule Engine for Complex Business Flows

1. Introduction

In many projects, serial or parallel business processes need to be orchestrated without tight coupling. Traditional strategy/template patterns lead to scattered files, making the overall flow hard to grasp. Liteflow provides a lightweight yet powerful rule engine that solves this problem from a global perspective.

2. Liteflow Rule Engine Overview

Liteflow is a plug‑and‑play rule engine that can quickly compose complex rule chains. It supports multiple rule file formats (XML, JSON, YAML) and various storage backends such as SQL, Zookeeper, Nacos, Apollo.

Liteflow architecture
Liteflow architecture

3. Component Types

Components correspond to nodes in the rule file. The main types are:

Ordinary Component – implements NodeComponent, used in when and then logic. Override process, iaAccess, isContinueOnError, isEnd as needed.

Switch Component – extends NodeSwitchComponent and implements processSwitch to decide the next node, similar to a Java switch.

If Component – extends NodeIfComponent and overrides processIf to return a boolean result.

3.1 Component Code Example

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

3.2 EL Rule File Syntax (XML)

# Serial execution
THEN(a, b, c, d);
# Parallel execution
WHEN(a, b, c);
# Nested serial & parallel
THEN(a, WHEN(b, c, d), e);
# Switch
SWITCH(a).to(b, c, d);
# Conditional
THEN(IF(x, a), b);

3.3 Data Context

The data context carries parameters between nodes. It is passed as a class type when executing a chain.

LiteflowResponse response = flowExecutor.execute2Resp(
    "chain1",
    initParam,
    CustomContext.class
);

3.4 Configuration (application.yml)

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

4. Business Practice Example

The article demonstrates an e‑commerce scenario where, after an order is completed, points are awarded, a message is sent, and SMS and email are dispatched in parallel.

Business flow
Business flow

The corresponding rule file (test_flow.el.xml) looks like:

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

Before executing the flow, input parameters are transformed into a custom context object for easy parameter passing.

Data preprocessing
Data preprocessing

During node execution (e.g., points grant), the context is accessed and business logic is performed. The isAccess method can be overridden to decide whether the node should run.

Node processing
Node processing

5. Summary

Most of Liteflow’s work—rule parsing, component registration, and assembly—occurs at startup, giving it high execution performance. It can log execution time for each business step and provide statistics. This article covered Liteflow’s core concepts, component implementation, rule syntax, configuration, and a practical e‑commerce use case.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaworkflowSpring 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

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.