Introducing LiteFlow: A Lightweight Rule Engine for Java Backend Development

This article explains how the LiteFlow rule engine can be integrated into Spring Boot projects to orchestrate serial and parallel business processes, describes its architecture, component types, configuration options, and provides practical code examples and a real‑world e‑commerce workflow.

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

In everyday development, developers often encounter serial or parallel business processes that lack clear relationships, making coordination difficult.

Combining strategy and template patterns can solve these problems, but hard‑coded implementations lead to scattered files; a rule engine offers a global view to manage such flows.

The article introduces liteflow, a lightweight yet powerful rule engine that can be used out‑of‑the‑box to compose complex rule chains quickly.

Architecture : LiteFlow supports multiple rule file formats (XML/JSON/YAML) and storage options (SQL, Zookeeper, Nacos, Apollo). It parses rules at startup, registers components, and assembles execution information for high performance.

Component Types :

Ordinary components (implement NodeComponent) for standard business logic.

Switch components (extend NodeSwitchComponent) to choose the next node based on conditions, similar to a Java switch.

Condition components (extend NodeIfComponent) that evaluate boolean expressions.

These components can be written in various scripting languages such as Groovy, JavaScript, Python, or Lua.

Rule Definition (XML example) :

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

Maven Dependency :

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

Configuration (application.yml/YAML snippet) :

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

Business Practice Example : In an e‑commerce scenario, after an order is completed, LiteFlow can orchestrate points granting, message sending, and parallel SMS/email notifications using a chain like:

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

The article concludes that most of LiteFlow's work (rule parsing, component registration) happens at startup, resulting in high execution performance and detailed timing statistics, and encourages readers to explore its concepts and usage further.

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.

Backend
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.