In every company's system, there are always some systems with complex business logic, these systems carry the core business logic, almost every requirement is related to these core business, these core business logic is lengthy, involving internal logic operations, cache operations, persistence operations, external resources fetching, internal other system RPC calls and so on. Over time, the project has changed hands several times, and the cost of maintenance will become higher and higher. All kinds of hard code judgments, branching conditions more and more. The code abstraction, reuse rate is also getting lower and lower, and the coupling between various modules is high. A small change in logic affects other modules and requires complete regression testing to verify. If you want to change the order of business processes flexibly, you have to make big code changes for abstraction and rewrite the methods. Real-time hot changes to business processes are almost impossible to achieve.
How to break the deadlock?LiteFlow is made for decoupling logic and orchestration, after using LiteFlow, you will find it becomes very easy to build a low-coupling and flexible system.
# Advantages of the LiteFlow Framework
If you want to rewrite or refactor complex business logic, LiteFlow is the most suitable. It is a lightweight and fast component-based rule engine framework, which orchestrates components, helps decouple business code, makes each business segment a component, and supports hot refresh rule configuration for instant modification.
With LiteFlow, you need to split the complex business logic into small components by code fragments and define a rule flow configuration. In this way, all components can be configured according to your rules for complex flow.
And all this, you just need to define the rules. LiteFlow provides extremely simple and easy-to-understand regular expressions.
Have you ever thought about how to implement the following complex logic flow in code?
At the same time, ensure that all components are flexible and changeable.
I believe that someone must be able to achieve it, but it requires a certain development cost.
And all of the above, with LiteFlow, you can easily get it!
# Design Principles of LiteFlow
LiteFlow is designed based on the workbench mode. What is the workbench mode?
Many workers surround a workbench in a certain order, and produce parts in sequence. The produced parts can eventually be assembled into a machine. Each worker only needs to complete his own task without knowing the production tasks of other workers. The resources required for each worker's production are taken from the workbench. If the workbench has the necessary resources for production, it will be produced. If not, it will wait until the resource is available. The parts made by each worker are also placed on the workbench.
This mode has several benefits:
- Each worker does not need to communicate with other workers. Workers only need to care about their work content and the resources on the workbench. This achieves decoupling and indifference between each worker.
- Even if workers change positions, the content of workers' work and the resources they care about do not change. This ensures the stability of each worker.
- If a worker is assigned to another workstation, the worker's job content and required resources remain unchanged, which ensures reusability.
- Because each worker does not need to communicate with other workers, it is possible to make real-time workstation changes as the production task proceeds: replacements, insertions, removal of some workers, so that the production task can also be changed in real time. This ensures the flexibility of the entire production task.
This pattern is mapped to the LiteFlow framework, where workers are components, the order in which workers sit is the process configuration, the workbench is the context, the resources are the parameters, and the final assembly of this machine is this business. Because of these features, LiteFlow can achieve uniform decoupling of components and flexible assembly.
# What scenarios are LiteFlow not suitable for?
Since LiteFlow has been open source, I've often been asked the question: How does LiteFlow do the flow between role tasks, similar to approval flow, where A should be approved by B after approval, and then flow to C role.
LiteFlow only does logic-based flow, not role-based task flow. If you want to do role-based task flow, it is recommended to useflowable (opens new window).
# What scenarios LiteFlow is suitable for
LiteFlow is suitable for businesses with complex logic, such as pricing engines, order submission processes, etc. These businesses often have many steps, which can be completely broken down into individual components according to business granularity and assembled for reuse changes. With LiteFlow, you get a highly flexible and scalable system. Because the components are independent of each other, you can also avoid the risk of changing one place and moving the whole body.