0
votes

I have the following use case: There are many (let's say 10000) accounts and each account (which can be identified by an id) should have its own set of rules. The rules of different accounts could contradict each other. For performance reasons it would be ideal if a new fact (which I know is only relevant to account xyz) would only be checked against the rules of account xyz.

Now as to my little understanding of drools there is only one rule space and one fact space for everything. Is that correct? That would mean I would have to make special rules for each account like

rule "rule 1 for account xyz"
    when
        $acc: Account(id == "xyz")
        <more conditions go here>
    then
        $acc.doSomething();
    end

This would result in tons of rules and probably slow execution. Can you please give me a hint how to handle this use case in an efficient way?

1
It's difficult to imagine how 10,000 different sets of rules can be maintained and deployed in good order. Is this multitude really essential in the sense that rule patterns and/or attribute usage in constraints differ? Or is it just a variety of literals acting as parameters? Or, perhaps, in between...? Has this been analysed by an expert?laune
It's only a few rules (let's say not more than 100) which contain parameters and can be applied to an account. Thus account A can have rule 5 with parameter x and rule 13 with parameter y. Account B can have rule 5 with parameter z and rule 23 with yet another parameter. It has not been analyzed by an expert that's why I was hoping to get some hints here at stackoverflow.user3528637
Just as I thought - more or less. Don't explode this into 10,000 knowledge bases up front. This "not more than 100" suggests that there is an "intelligent" solution that avoids the 10k rules.laune

1 Answers

1
votes

Now as to my little understanding of drools there is only one rule space and one fact space for everything. Is that correct?

No, that is not correct. You can have multiple KnowledgeBases (KieBases in Drools 6.x) with the specific set of rules you need. From a particular KnowledgeBase you can create as many sessions (fact-spaces) you want.

In your case, having a specific KnowledgeBase for each of your accounts seems to be the right decision.

Hope it helps,