3
votes

Am looking for some advice on the design of an application. As I'v signed an NDA I can't reveal too much about the actual business but will try to explain the requirement.

Essentially, we want to develop an application that will take a decision based on a customers credit profile. We will take data from a suitable provider (eg. Experian) and match it against the business rules. If the customer meets those rules, they get a green flag to be passed to the next process (and possibly another system, but am not worried about that for now); if not, they will get a red flag and not get passed on.

The client has indicated that they would like the business rules to be modifiable i.e. something that they can amend and thats not hard coded or stuck in the code somewhere. They have defined a set of rules as a 'template'. The system will only have one active template at a time, but over its lifetime might have many templates.

These rules would be composed of multiple operators checking different data types. Each phase/step of the rules would be allocated a certain weight. An example of a 'template' would be

  • Is the customer male = 10 points
  • Is the customer female = 20 points

  • Is the customer between 25 and 35 years of age? = 20 points

  • Is the customer less than 25 years of age? = 10 points

  • Does the customer earn between $30000 and $50000 per annum = 20 points

So as you can see, there are comparisons/operators of various types (boolean, integer etc).

I am looking for a framework/advice on which I can build these 'templates'. This is a web job, so we know that we'll definitely be using a DB of some sort. The technology has not yet been decided, but would probably be between PHP & .NET. We think at this stage that a lot of this will be done in SQL (and would like to see if this is a good idea to pursue)

Are there any sample applications out there that I could go through? Has anyone done work of this nature before?

Thanks!

3
Beware of trying to model complicated business rules using SQL. Edge-cases can quickly turn the thing into gazillions of tables and rows. See this (somewhat controversial) video on ACL for an example.Denis de Bernardy

3 Answers

1
votes

I don't think that letting your customers write their own rules in SQL and then executing those is a smart idea. Firstly, you could run into security issues (for instance, if they access parts of the database they shouldn't), and you reveal too much implementation specifics (what if they start using DBMS-specific operations, and you later decide to replace the DBMS).

Depending on the amount of work you want to put in here, this sounds like a good job for a Domain Specific Language. @Ozair suggested BPEL, but it might be overkill.

0
votes

If all your rules are that simple, you could use something like:

Rule {
    ruleId,
    templateId,
    comparisonType,
    fieldName,
    minValue,
    maxValue,
    scoreIfPassed
}

Template {
    templateId,
    rules
}

...so a Rule is associated with a Template, and specifies a comparison type to apply (like 'greaterThanMin', 'lessThanMax', 'exactValue', 'insideRange', etc.) to a given field. Then you can do:

user.score = 0;
rules = currentTemplate.rules;
for each rule in rules do
    if rule.comparisonType == 'exactValue' && user[field] == minValue
        user.score += rule.scoreIfPassed;
    else if rule.comparisonType == 'insideRange' && user[field] > minValue && user[field] < maxValue
        user.score += rule.scoreIfPassed;

    ...
end