跪拜 Guibai
← All articles
Backend

How Lalamove Replaced Scattered if/else Logic with a Visual Rule Engine

By 货拉拉技术 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most teams manage business rules through a combination of hard-coded conditionals and unstructured config-center entries, which makes frequent policy changes risky and slow. Lalamove’s approach shows how to retrofit governance—approval, dual-run comparison, grayscale rollout, snapshot rollback—onto a local rule-execution SDK so that business operators can change rules without a code release and without blowing up production.

Summary

Frequent business rule changes—whether an address edit is allowed, which risk strategy fires, or how an invoice switch behaves—often degenerate into tangled if/else blocks or brittle JSON blobs in a config center. Lalamove’s rule visualization platform replaces that with a management console where operators compose rules from typed fields, reusable judgment components, and EL-orchestrated chains. The console enforces test-case validation before any rule ships.

Under the hood, the platform separates the management plane from the runtime plane. Rules are published as Chain JSON to Apollo, pulled and cached by a configuration SDK inside each business service, and executed locally by a rule SDK built on LiteFlow. That local execution keeps latency low and avoids a hard dependency on a remote rule service. Every release generates a snapshot, and risky changes can first run in a shadow compare mode or roll out through percentage-based grayscale switching.

Since going live, the platform has cut the cost of policy changes that previously required code releases, made rule changes auditable and instantly rollbackable, and begun accumulating a cross-domain library of reusable fields and components. The core insight is that a rule engine’s value comes less from the visual editor and more from the governance wrap around it: verify before publish, approve with change diffs, dual-run to observe impact, and roll back with a single click.

Takeaways
Business rules are modeled as spaces, categories, typed options, reusable components, and EL-orchestrated chains rather than raw JSON.
Rules are published as Chain JSON to Apollo; each business service pulls and caches only the chain keys it needs.
Execution runs locally via a LiteFlow-based SDK, avoiding a remote call to a rule service on every request.
A shadow compare chain (key suffix `Compare`) runs new rules side-by-side with the current version and logs differences via JsonDiff without affecting production results.
Grayscale traffic switching uses a `flowPercent` field; when set, a random percentage of requests executes the new chain.
Every publish creates a snapshot, enabling one-click rollback to a previous chain version.
Hot updates flow from Apollo push → local cache update → ChainHelper reload → LiteFlow FlowBus refresh, with a scheduled pull as fallback.
Test cases are constructed and executed directly in the management UI, removing the need to hit real business endpoints for regression checks.
Conclusions

Lalamove deliberately chose not to build a remote rule-execution service; local SDK execution keeps latency predictable and avoids a new single point of failure.

The platform’s real differentiator is not the visual editor but the governance pipeline—test, approve, dual-run, grayscale, snapshot-rollback—that wraps every rule change.

Using LiteFlow as the execution kernel is a pragmatic choice: it lets the team focus on rule-asset management and release governance instead of reinventing a process engine.

Registering a shadow compare chain automatically for every chain key means dual-run capability is a platform primitive, not an afterthought bolted onto specific rules.

The fallback from a grayscale release version to a default version in the config server prevents a silent empty-config bug when a targeted rollout key is missing.

Concepts & terms
Chain JSON
The serialized, SDK-consumable representation of a rule chain, containing the chain key, EL expression, component list with scripts, version, and grayscale percentage. It is the contract between the management console and the runtime.
Dual-run comparison (双跑对比)
A safe rollout technique where a new rule version executes as a shadow chain alongside the current production chain. Both results are computed, but only the main chain’s result is returned; differences are logged via JsonDiff for observation before any traffic is switched.
LiteFlow
A lightweight Java flow-execution framework that the platform uses as its runtime kernel. It parses EL expressions to orchestrate Node execution, manages a registry of Chains and Nodes (FlowBus), and provides the FlowExecutor entry point.
EL expression (in LiteFlow)
A domain-specific expression language for defining the orchestration of rule components. For example, THEN(a, b, c) runs components sequentially, while IF(cond, x, y) adds branching. The visual chain canvas compiles down to these expressions.
Script component vs. Java component
Two component implementation strategies. Java components are pre-compiled Spring beans for stable, complex logic. Script components carry their logic as a script string inside the Chain JSON and are dynamically registered as LiteFlow script nodes at runtime, suiting frequently changing conditions.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗