Design and Evaluation of a Rule Engine for Dada Logistics Notification System
This article describes the background, requirements, architecture, script language selection, performance testing, and future plans of a rule engine used to send notifications to couriers in Dada Logistics, highlighting the trade‑offs among Groovy, MVEL, SpEL and Aviator.
Background In 2020 Dada Logistics experienced rapid growth, onboarding many merchants and business scenarios such as food delivery, supermarkets, flowers, and personal city‑wide delivery, requiring high fulfillment rates and efficiency, which called for fine‑grained operational decisions.
Case A public module sends notifications to couriers based on business type, scenario, courier attributes, event type, and other parameters, deciding the template and delivery method.
When decision logic is simple, hard‑coding works, but as the number of upstream services and complexity increase, hard‑coded logic becomes scattered, tightly coupled, and hard to iterate. A rule engine was introduced to separate decision logic from system code, enabling independent evolution, centralized management, and rapid iteration.
Requirement Extraction Beyond basic decision capability, the production‑grade rule engine must provide:
Real‑time : lightweight rule changes that take effect immediately without complex deployment.
Easy Integration : friendly APIs that lower learning cost for adopters.
Fault Tolerance : graceful degradation in abnormal situations.
Security : pre‑release validation to ensure new rules meet expectations.
Rule Engine Architecture The design consists of two parts: configuration management and configuration usage, illustrated in two diagrams (Fig 1 and Fig 2). Fig 1 shows a server‑side and client‑side split with Apollo as the configuration center for real‑time rule distribution.
Real‑time is achieved via the server/client split and Apollo configuration center.
Easy Integration is provided through a jar‑client offering a unified API.
Fault Tolerance is handled by configurable degradation flags for variable calculation and rule matching, with enable/disable switches in the management UI.
Security is ensured by an online debugging feature in the management platform before publishing rules.
Script Language Selection The core decision engine needs a scripting language. In Java, common choices are Groovy, MVEL, Aviator, and Spring EL (SpEL). They were compared on functionality, performance, maturity, and learning cost.
Functionality Comparison
Feature
Groovy
SpEL
MVEL
Aviator
Logical expression
Supported
Supported
Supported
Supported
Arithmetic expression
Supported
Supported
Supported
Supported
Ternary expression
Supported
Supported
Supported
Supported
Regex match
Supported
Supported
Supported
Supported
Object property
Supported
Supported
Supported
Supported
Object method
Supported
Supported
Supported
Not supported
If‑else
Supported
Not supported
Supported
Not supported
Assignment
Supported
Not supported
Supported
Not supported
Java library access
Supported
Supported
Not supported
Not supported
The most feature‑rich language is Groovy, followed by MVEL, SpEL, and finally Aviator. Although both Groovy and SpEL can use Java libraries, SpEL’s syntax is considered more “quirky” compared with Groovy’s seamless integration.
Performance Execution time (ms) for the expression "i>10000 && i<100000" was measured at various iteration counts:
Executions
Groovy
SpEL
MVEL
Aviator
1,000
8
12
6
6
10,000
24
38
13
12
100,000
69
72
46
57
1,000,000
1,617
2,781
1,008
988
Performance ranking: Aviator > MVEL > Groovy > SpEL.
Technology Maturity All four languages have active communities, but Groovy enjoys the largest adoption.
Learning Cost Groovy, MVEL, and Aviator share Java‑like syntax, resulting in minimal learning effort, whereas SpEL requires learning its own syntax.
Selection Summary SpEL is eliminated due to limited functionality and higher learning cost. Aviator is also excluded because it does not support method calls. Between Groovy and MVEL, Groovy offers richer features and greater maturity; its performance, while not the best, meets business needs, leading to the final choice of Groovy.
Pitfalls Encountered By default, each execution of the same Groovy script recompiles it, creating a new class and loading it, which increases Metaspace usage and can cause memory leaks and performance degradation. Caching compiled scripts using an MD5‑based key mitigates this issue.
Future Plans The rule engine now serves dozens of scenarios; upcoming work includes improving the configuration UI for better user efficiency and implementing fine‑grained data permissions for different roles and business contexts.
Author Bio Ma Jian, Senior Engineer at Dada Group, joined in 2020, responsible for the development of Dada Express fulfillment services, aiming to provide high‑quality solutions for the instant delivery industry.
Dada Group Technology
Sharing insights and experiences from Dada Group's R&D department on product refinement and technology advancement, connecting with fellow geeks to exchange ideas and grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.