Building Business Rule Engine
It provides an overview of what the Business Rules Engine is and describe one of the modern approaches to building it that you may consider when building this kind of technology
building a Business Rules Engine which enables business automation for all business verticals and also has all the capabilities and potential to serve well to large enterprises with the deep sense of sophisticated and complex solution that meet the tough scalability, maintainability, and extendability.
Business Rule Engine and it’s importance
Business rules engines have been around in the various verticals for quite a long time in one form or another and there are some definitions given for pretty every term we are going to use. Let’s start with a “business rule” — there is a well-known definition for this term. So a “business rule” is:
Well, I found the basic term in T. Morgan, Business Rules and Information Systems. Boston.
A statement that defines or constrains some aspect of the business. It is intended to assert business structure or to control or influence the behavior of the business.
Business rules have a very wide scope and may be applied to any aspect of the business operations. For example, the rule “When a customer walks into your store, welcome him/her with a warm smile and a friendly “Hello” is applied by the company employee when meeting with customers. Another rule may define or constraint the approaches to solving routine tasks by a specific role in a company. A majority of business processes has become partially or fully data-oriented. This has led to the transformation of business rules so that they became software-oriented, for example, the business rule “When a customer buys something from your store, give them a call later asking if they would like to buy other related goods or show the related products based on order history” has transformed to a more modern “When a customer buys something from our online store send him an email listing other related goods later”. Nowadays many companies deal mostly with data in their daily operations. Taking into account, that the majority of businesses of all sizes have integrated technology solutions to their business activities
A business rule can be represented as a sequential series of atomic commands. The commands may include conditional data analysis, time wait commands, action execution commands, etc. The business rule example “When a customer buys something from our online store send him/her an email listing other related products later” is a good and generic one and many other business rules can have a very similar logical structure:
Sequential series of events
Processing of the business rule
Business rule processing starts when a particular business event happens. It can be anything. for example, a user has logged in, a purchase has been made, some amount of money has been transferred to/from your account etc. This kind of activity should be tracked and the Rule engine should be informed about it via some communication protocol.
The whole concept is being built on microservices based architecture
1. Business Event Consumer
It listens to all the business trigger events via declaring a queue and binding it to a specific route exchange on a RabbitMQ server.
It holds information about what has happened as well as some relevant supplementary data. The business event may be identified with an attribute of any kind passed in the data packet, for example, a string purchase.completed. The data packet is then consumed by business event consumer microservice.
It then queries the manager microservice if there are any business rules in the database that have the appropriate rule trigger for the incoming business activity event. And if there is such matching business rule, the manager microservice returns the initial command data to the business event consumer microservice. This data retrieval from the manager can then be done to process it further
2. Initial Rule Processing
It consumes the incoming data packet and does it’s logic based on initial state of rule, then it queries rule manager if there are subsequent commands in the business rule to fulfil. And if so, it receives the next command data and sends both business event data and next command data to the internal RabbitMQ server. Yes, it now looks like linked list traversal, and when the rule has branches it’s a tree traversal. This is how the business rule is being processed command-by-command. Another important thing here — it that context, the business event data is passed to every child command. It’s a context of the unique business rule execution. It can be used later in the data analysis command processor and action command processor.
3. Pre Processing Tasks
Every rule will have their own pre-processing tasks prior to getting entered into action command processor. If It’s get validated by then ready to move to action command processor, It not then it needs to be re-validated and revert the process. For example: to send emails to store customers, your emails needs to be verified and make sure that your customers should have opted in to receive promotional emails from your store.
4. Finally, there is a message in the internal exchange manager, that is ready for the action command processor to be consumed. If the business rule execution flow has come so far to this command, that means that in this branch of the rule every condition that was there in the data analysis command was trust worthy, the execution flow was not interrupted and ready to process. The action command processor executes the final action, for example: send an email to the store customers.
5. Post processing Tasks
Post your rules actions will be satisfied with all conditions, There has to be some kind of acknowledgement to and from. For example: When email has been sent out to customer, The emails metrics should be generated after some hours to monitor the rules effectiveness.
The blood vessel and godfather of the rule engine is the communication of data packets. For the system to remain operational under high load, the internal message exchange should be highly reliable