Skip to main content
1 of 5

How to design a Rule Engine Validation System to be asynchronous and highly performant!

I am implementing a validation system which has some constraints, there are category of users let's say 30 and for each category there are number of rules. Actually there are 100 different rules.

I have a multimap which maps given user_category_id to list of rule_id's.

Constraint 1. The rule should only execute if its enabled for that user category. Rules are differently configured based on whether its for update or insert.

Here I am thinking of using Strategy pattern to validate the rules.

From the context I will pass as parameter the (user_category_id, rule_id's list, and whether its for Update or insert). Each rule will be a separate class with methods to get its rule id value, execute method for the given user category and logic based on whether its for update or insert.

So the context class will have the multimap for the user_category_Id to the rule_id. and the value for whether the rule validation is being done for update or insert.

In the IStrategy interface will be having the signature of the method. But what would be the return type of the method I am not sure of.

Last part is how to design the rule logic. There are hundred of different rules. How to go about this task? Should I put all the 100+ rules into separate classes? I feel I should be using Strategy pattern but I am not clear about how to carry out the implementation?