Risk control rule engine construction and challenges

introduction

If the decision-making engine is the brain of risk control, then the rule engine is an important component of the brain. It arranges various rules against illegal production, which is the accumulation of years of expert experience in combating illegal production. This article will introduce you to the composition and implementation of the rule engine.

background

What is a rules engine?

A rule engine can help enterprises separate business decisions from application code and write business rules using predefined semantic modules. This allows enterprises to more flexibly manage and modify business rules without modifying application code.

A rule engine can accept data input, interpret the data according to business rules, and make business decisions. These business decisions can be automated or human intervention.

A rule engine usually consists of the following parts:

  • Rule base : The rule base contains all available rules. These rules can be pre-defined or dynamically generated.
  • Strategy : Used to manage rules, it is a conditional assembly of rules, such as scorecard strategy, worst match strategy, etc.
  • Rule execution engine : responsible for the execution of rules. Read all available rules in the rule base, and execute the rules according to the conditions of the rules.

Why do you need a rules engine?

The rule engine can help enterprises manage and execute business rules more effectively, and improve the quality, efficiency and reliability of decision-making.

The features are as follows:

  • Separate business decisions from codes : operators can manage and modify business rules more flexibly and effectively without modifying business codes, saving confrontation time
  • Improve decision quality : the rule engine automatically makes decisions according to business rules without relying on human intervention
  • Efficiency improvement : After the rules are configured, they can be permanently and automatically executed, reducing manpower consumption
  • Stability : reduce releases, reduce testing, and reduce human errors

design implementation

Technology selection

When choosing a rules engine, you need to consider the following points:

  • Business requirements : The rule engine should be selected according to the business needs of the enterprise. If an enterprise needs to execute a large number of rules quickly, it should choose a rule engine with higher performance.
  • Technology platform : Choose a rule engine that is compatible with the company's existing technology platform. If your enterprise is using the Java technology platform, you should choose a rules engine that supports Java.
  • Cost : Consider the purchase cost, implementation cost, and operating cost of the rules engine. Open source is also a selection factor for many technical teams.
  • Maintainability : Choose an easy-to-maintain rule engine that can quickly modify and update rules when needed.
  • Market share : Choose a rule engine with a higher market share, and get better technical support and training when needed.
  • Technical support : Choose a rule engine that provides better technical support, so that you can get timely help during use.

Of course, if you have enough manpower, you can consider implementing the rule engine yourself. The self-implemented version of the rule engine is definitely more flexible, but it needs a longer period of verification and testing in terms of performance and stability.

The following are popular open source rule engines on the market:

rule engine Introduction
JBoss Drools JBoss Drools is an open source rules engine that supports Java and other languages.
OpenRules OpenRules is an open source rules engine that supports Java and other languages.
Hippo Rules Engine Hippo Rules Engine is an open source rules engine that supports Java and other languages
Apache Flink Apache Flink is an open source stream processing framework that can also be used as a rule engine
Easy Rules Easy Rules is a Java-based open source rule engine framework, which provides a simple and easy-to-use API, allowing developers to easily use the rule engine.
Implementation of rule engine based on Groovy Groovy is a dynamic language that runs on the Java platform. Because of the simplicity of Groovy's syntax, a rule engine can be implemented using Groovy.

Rule Engine Terminology

  • Rule (Rule) : A rule is a statement describing the rules or conditions of a business decision. Rules usually consist of two parts: conditions and actions. Conditions describe the judgment that the rule is triggered, and actions describe the operations performed by the rule.
  • Fact : Facts are data that describe business scenarios. A fact can be a single data item or a set of data. The rules engine triggers rules based on the facts.
  • Decision Table : A decision table is a data structure that represents rules in tabular form. Decision tables usually consist of condition columns and a result column. When the values ​​of the condition column are all satisfied, the decision table will trigger the rule of the result column.
  • Rule Set : A rule set is a data structure composed of rules. Collections of rules are usually stored in a tree structure, each rule has a condition and an action. When the conditions are met, the rule set will execute the action of the rule.

Rule configuration analysis

In the end, the rule engine needs to be delivered to the operation personnel for configuration and use, so it must be able to meet flexible configuration arrangements and be easy to understand in order to maximize its power.

rule configuration


illustrate:

  • Trigger conditions : any one, satisfy all, custom. Among them, customization is the most flexible, and users can use conditional expressions to configure any desired trigger and or conditions
  • Variable (indicator) : left value, the indicator is the value derived from input data, or queried, or calculated
  • Comparators : equal to, not equal to, contains, belongs to, greater than, less than, null, etc.
  • Threshold : rvalue, compared with the value calculated by the indicator, if the comparator relationship is established, the current rule is considered to be hit
  • Default value : When the indicator execution fails or times out, the value returned by default

policy configuration


illustrate:

  • Scorecard mode : According to the sum of the scores obtained by hitting each rule, the decision of whether to hit the corresponding score segment is determined
  • Worst match : as long as there is a rule hit, it is rejected immediately
  • Threshold : If it is the scorecard mode, you need to set three segments and specify the threshold

performance tuning

The decision engine carries all the risk decisions of the enterprise business every day, and the peak QPS is basically over 10,000. However, the risk control decision-making time needs to be short enough, and it is a big challenge to return the decision results as soon as possible without affecting the business.

From past tuning experience, the rule engine can be optimized from the following points:

  • Parallel execution of rules : A decision flow may contain N rule nodes, and each rule node contains M rules, making full use of the advantages of multi-core CPUs to maximize its power, but at the same time multi-threaded data security issues need to be considered
  • Preloading indicators : The execution of rules is in memory, but the required indicator values ​​are often obtained by calling external systems, one is network overhead, and the other is indicator calculation overhead. Before executing the rule set, all indicators can be preloaded once and then cached, so that it will be much faster to fetch values ​​directly from memory during execution. But you need to pay attention to cost issues (such as payment indicators, storage costs, architectural complexity, etc.), waste call issues (pre-rules have been rejected), etc.
  • Rule loading precompilation : The first loading of rules is often time-consuming. At this time, it is best to click on it warm upso that it can be executed immediately after the traffic comes in. However, using precompilation may increase the startup overhead time of the system, and corresponding balance work needs to be done
  • Rule execution optimization : The order of rule execution may not be considered when operating and configuring rules, but the program can be intelligently arranged during execution. By adding the and relationship, the time-consuming and costly indicators are executed at the end as much as possible, and memory indicators are executed first. If they are hit, they will be asserted directly, and subsequent indicators will not be 与或executed again , saving顺序 time . To achieve this, it is necessary to carry out more detailed classification and metadata management of indicators, and the cooperation of data in the whole domain is required, which is a big challenge for risk control, an interface that requires big data.

Summarize

The importance of the rule engine in the overall framework of risk control is unquestionable, and its stability is directly related to the performance and data quality of risk control decisions. At the same time, for operations, a good decision-making engine is flexible enough and intelligent enough to meet the requirements of rule data arrangement, and it can go online immediately.

Exciting past issues
A must-have for performance optimization—flame graphs
How did I get involved in risk control
Flink’s real-time feature implementation in risk control scenarios

Welcome to pay attention to the official account: Cuckoo Chicken Technology Column
Personal technology blog: https://jifuwei.github.io/

Guess you like

Origin blog.csdn.net/weixin_43975482/article/details/128575736