Idea

The idea is to take complex un-structured data, convert it to simple primitive data types (usually called features or facts). And then have a logical rule which can run with the set of features/facts & evaluate if the rule is true or not.

Rule engine’s excel when you have a complex discrete function to compute to decide if it evaluates or not. This will be more clear with examples explained below.

Use cases

Deciding on user status

Let’s say you have a user object with around five statues. And let’s say the user status is decided on a combination of data points like:

  • if the user updated name, gender and other basic information. move the user from INITIATED to VERIFICATION_PENDING.
  • if the admin approves the data and confirms that the data is valid. move the user from VERIFICATION_PENDING to VERIFIED. In this case, the function is discrete in the sense that the result is one of three states. And a rule for each state would solve the issue of structuring the business domain rule in a way business people can visualize, edit & back test the rule.

Deciding on user loan eligibility

Let’s say you are running a fin-tech which gives out loans. Deciding if a user is eligible for a loan or not is a discrete function with a bool output. Having a complex, large rule which uses hundreds of features for rejection helps in structuring the domain complexity in a way both business & engineering can manage it better.

Building it from scratch

We’ve built a simple rule engine from scratch over at From scratch.

Battle tested libraries

  • json-rules-engine: Javascript library in which rules are written in JSON, this is extremely useful if you want to to store and version rules in the database.