Backend Development 18 min read

Baidu Tieba Rule Engine: Architecture and Implementation

The Baidu Tieba rule engine is a low‑code platform that lets non‑developers define, compile, and execute dynamic business rules through modular components, variable handling, JSON‑based rule trees, and customizable disposition handlers, supporting synchronous, asynchronous and parallel execution to reduce hard‑coded logic, deployment frequency, and maintenance effort.

Baidu Geek Talk
Baidu Geek Talk
Baidu Geek Talk
Baidu Tieba Rule Engine: Architecture and Implementation

The article introduces the Baidu Tieba rule engine, a low‑code platform that enables non‑developer staff to configure and modify business rules without writing code. It explains why a rule engine is needed for rapidly changing operational policies and rights management.

Typical usage scenarios include:

Single‑rule iteration, e.g., 用户标签->包含A关键词->权益A and similar rule chains.

Continuous integration of new capabilities such as image‑recognition models, where each new model adds RPC calls and multiplies possible rule combinations.

To avoid hard‑coded logic that would require frequent deployments, the rule engine centralizes these dynamic rules.

Engine composition consists of four modules:

Component services : thin wrappers around third‑party services (e.g., image‑model RPC). Developers declare a static function and specify its execution mode – sync (blocking), async (before/after callbacks), or parallel (curl_multi parallel calls).

Variable platform : variables (or operators) are the inputs for rule evaluation. They can originate from predefined constants, business request parameters, or the results of component calls. The platform allows simple code editing to transform or derive new variables.

Rule engine platform : rules are stored as JSON node trees. Nodes represent condition checks, recall actions, exemption actions, or switch branches. Supported operators include numeric comparisons (>, <, >=, <=, ==, !=), string length ( len ), array count ( count ), and word‑list membership.

Disposition methods : custom RD‑implemented handlers that execute the final business logic (e.g., returning true/false, rule IDs, or special flags). Their update frequency is low and they are typically reused across many rules.

Implementation details :

The compilation process extracts all defined variables, resolves recursive dependencies, and emits PHP‑style code snippets.

Rule files (JSON node trees) are merged with variable definitions, then optimized: duplicate variable names receive a _n suffix, unused variables are removed, and identical function calls are deduplicated.

Async and parallel functions are split into before (request) and after (callback) phases, allowing independent RPC calls to be issued via curl_multi and results to be processed later.

The final executable consists of units with fields name , func , param , and cond . When cond evaluates to true, the corresponding function runs, producing a value that may feed subsequent units or trigger a recall.

The rule engine thus provides a flexible, graphical way for product and operations teams to manage complex business logic, reduces development workload, and improves maintainability while supporting high‑performance asynchronous and parallel execution.

rule enginebackend developmentlow-codeParallel Processingservice architectureAsynchronous Execution
Baidu Geek Talk
Written by

Baidu Geek Talk

Follow us to discover more Baidu tech insights.

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.