Rule resolution process in pega

What is the Rule resolution process in Pega?

Rule resolution is a search algorithm for the Pega process commander to find the most appropriate rule instance of a rule to execute in any situation. This is an internal background process of the Pega rules process commander.
Rule resolution process

What are the inputs for the Rule resolution process?

The process commander needs the below inputs to perform the rule resolution algorithm and to return the best match for the situation.
  1. Rule key  - Apply to class, Rule name, and Rule type. Ex: Section CL: TP-Training-Work ID: PHTemplate
  2. User's Ruleset stack(list)
  3. Class inheritance of the current rule's applies to class.
  4. Circumstance (Property and Date).
  5. Rule availability
  6. User's access roles and privileges

How the rule resolution process works?

When a particular rule is referenced (or need to be executed at runtime) in the application, the rule resolution process will first try to locate the instances of that referenced rule in the Rules cache. So the Rule Resolution process will be executed in two ways. When the

1. Rule instances are found in the Rules cache.
2. Rule instances are not found in the Rules cache.

Rule instances are found in the Rules cache

If the rule resolution was already run for the rule, the rules cache has a list of all possible rule candidates. When the rule instances are found in the rules cache, Pega will follow the below steps to finalize the rule and execute it.
  1. Find rule in the rules cache
  2. Find the best instance and check for duplicates
  3. Confirm the rule is available for use (Availability is not set to Block).
  4. Verify the user is authorized to use the rule
Rule resolution process

Rule instances are not found in the Rules cache

When the rule instances are not found in the rule cache, Pega runs a subprocess (from the above flow) to populate the rules cache and once the cache is populated then it will find the best match by eliminating duplicates and checks the rule availability and verifies if the user is authorized to access the rule.

Populating rules cache

Populate rules cache
  1. Choose all instances with the correct purpose.
  2. Discard rules where Availability = Not Available
  3. Discard inapplicable rulesets and versions.
  4. Discard all candidates not defined in a class in the ancestor tree.
  5. Rank remaining rule candidates.
Ranking rules

  a. Sort the remaining rule candidates.
  b. Remove rule candidates with an Availability set to Withdrawn
  c. Determine default rule candidate.

       6. Set the rules cache.
       7. Find the best instance and check for duplicates.
       8. Confirm the rule is available for use (if the rule Availability is set to Block).
       9. Verify the user is authorized to use the rule.
 
We will see two scenarios in detail and how Pega uses a rule resolution algorithm to find the best instance of a rule. 

1. Rule instances are found in the Rules cache

Let's take a section AllocateBudget in a Service Request case. The section will be displayed after the Inspection review has done in the Review stage and the AllocateBudget section is circumstanced with property "IssueSeverity=High".

rule resolution with example

A Service Request is raised and IssueSeverity is Medium

Find the rule in the rules cache - example

Users ruleset stack:

user ruleset stack

Rule resolution algorithm will follow the below steps to find the best match as the instances are found in the rules cache.
Rule resolution steps in Pega
  1. Find rule in the rules cache
  2. Find the best instance and check for duplicates
  3. Confirm the rule is available for use (Availability is not set to Block).
  4. Verify the user is authorized to use the rule

1.Find the rule in the rules cache.

Pega searches the Rules Cache for a list of all possible rule candidates for the rule "AllocateBudget" section and it finds below three instances.
Find the rule in the rules cache

2. Find the best instance and check for duplicates.

From the above three instances, Pega has to pick one suitable rule accordingly. The best instance will be picked up by Pega where the instance matches with a Property or Date circumstance or a Default rule instance if no exact circumstances are found.

When a rule that matches any of these conditions is found, the rule resolution algorithm checks whether the next rule in the list is equally correct. If a subsequent match is found, Pega sends a message that there are duplicate rules and stops processing. If no other matches are found, Pega prepares to use the rule that matched the listed conditions.

In this case, the section "AllocateBudget" is circumstanced with Property IssueSeverity=" High" but in the case creation user has selected Issue severity as "Medium".
The first instance from the list will be skipped as the circumstance is High but Pega is looking for Medium (Medium is selected in the Service Request case creation).
The second instance has a date range specified as Before 01 Jul 2020. The current system date is 17 July 2020 (Case creation date). The date range circumstance is not met, so the ruling candidate is skipped and Pega moves to the next rule in the list. 
The third instance does not have a qualifier, so the system selects this rule.

Find the best instance and check for duplicates

3. Confirm the rule is available for use.

In this step Rule resolution algorithm checks for the rule availability, if the rule availability is "Blocked", execution is halted.
From the above list, the third instance is qualified and the availability is "Available" so the rule is considered available to run.
Confirm the rule is available for use

4.Verify the user is authorized to use the rule.

This is the final step in the rule resolution algorithm, in this last step Pega checks if the user has the authorization to access the rule. It checks if the user has the privileges required by the rule.

In this case rule (section - AllocateBudget) have no privileges so this instance will be selected and executed. 

2. Rule instances are not found in the Rules cache.

Pega uses a caching mechanism called the Rules Cache to help ensure rule resolution operates efficiently. When the rule instances are not found in the Rules cache Pega uses multiple steps to populate the rules cache and determine the best instance to select and execute.
Populate rules cache
In the Populate rules cache process we have the below steps:
  1. Choose all instances with the correct purpose.
  2. Discard rules where Availability = Not Available
  3. Discard inapplicable rulesets and versions.
  4. Discard all candidates not defined in a class in the ancestor tree.
  5. Rank remaining rule candidates.
  a. Sort the remaining rule candidates.
  b. Remove rule candidates with an Availability set to Withdrawn
  c. Determine default rule candidate.

1. Choose all instances with the correct purpose.

This is the first step in the populate cache process where the rule resolution algorithm generates a list of all rules that match the purpose of the referenced rule (Section - AllocateBudget). 
The purpose of the rule is the combination of Apply to class, rule type, and rule name  (TP-Training-Work-ServiceRequest Rule-HTML-Section AllocateBudget) but in this step rule resolution algorithm excludes Apply to class and creates a list with rule type (Rule-HTML-Section) and rule name (AllocateBudget). In this example, it creates a list with 23 rules where the section name is AllocateBudget. At the end of this cache, the population process Pega will identify the list of rules and put them in the rules cache.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Not Available

ServiceRequest

02-02-01

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-02-01

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

4

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

5

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

6

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Blocked

ServiceRequest

01-01-01

 

7

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

8

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

9

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Not Available

ServiceRequest

02-01-01

 

10

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

11

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

12

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

13

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

14

TP

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

15

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 

16

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

17

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

18

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-01-01

 

19

TP

Rule-HTML-Section

AllocateBudget

Available

TP

01-01-01

 

20

PH-Online-Work-OneHelp

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-06

 

21

PH-Online-Work- OneHelp

Rule-HTML-Section

AllocateBudget

Not Available

OneHelp

02-01-05

 

22

PH-Online-Work

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-01

 

23

PH

Rule-HTML-Section

AllocateBudget

Available

PH

01-01-01

 





















































































2. Discard rules where Availability = Not Available

In this step algorithm will discard and remove the rules where availability is "Not Available". 

From the above list, we have 3 rules where availability is set as "Not Available". After removing three rules we have a list with 20 rules.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-02-01

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

4

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

5

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Blocked

ServiceRequest

01-01-01

 

6

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

7

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

8

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

9

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

10

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

11

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

12

TP

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 

13

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 

14

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

15

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

16

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-01-01

 

17

TP

Rule-HTML-Section

AllocateBudget

Available

TP

01-01-01

 

18

PH-Online-Work-OneHelp

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-06

 

19

PH-Online-Work

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-01

 

20

PH

Rule-HTML-Section

AllocateBudget

Available

PH

01-01-01

 











































































3. Discard inapplicable rulesets and versions.

In this step, the rule resolution algorithm uses the operator's ruleset list(stack) to determine which rules the operator can access. Below is the Ruleset stack for the operator and the operator has ServiceRequest:02-01 and TP:03-01 rulesets in the stack.
ruleset list

  • Each rule in the lit must belong to a ruleset in the operator's ruleset list.
  • Each rule's ruleset Major version must have the same as the operator's ruleset Major version.
  • Each rule's Minor version less than or equal to the specified Minor version number listed in the operator's ruleset list.
  • Rulesets that are not there in the Operator's ruleset stack will be eliminated. In this example, OneHelp and PH rulesets are not listed in the operator's ruleset list.
After considering the operator's ruleset list and the above points, rule resolution has identified below 11 rules which are not satisfying the conditions and will be eliminated from the list.

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-02-01

 

5

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Blocked

ServiceRequest

01-01-01

 


7

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 



12

TP

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

01-01-01

 





14

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

15

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-10-01

 

16

TP

Rule-HTML-Section

AllocateBudget

Available

TP

02-01-01

 

17

TP

Rule-HTML-Section

AllocateBudget

Available

TP

01-01-01

 

18

PH-Online-Work-OneHelp

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-06

 

19

PH-Online-Work

Rule-HTML-Section

AllocateBudget

Available

OneHelp

01-01-01

 

20

PH

Rule-HTML-Section

AllocateBudget

Available

PH

01-01-01

 


















After eliminating the above 11 rules which are not satisfied with the conditions we have 9 rules on the list.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

4

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

5

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

6

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

7

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

8

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

9

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 






























4. Discard all candidates not defined in a class in the ancestor tree.

In this step, the algorithm uses the Ancestor tree which is nothing but Rule's inheritance. The algorithm examines rules (Here the rule is Section -AllocateBudget) Apply To class (TP-Training-Work-ServiceRequest) to determine if the rules from the above list are there in the inheritance hierarchy of the referenced rule (section in this case). 

From the above list of 9 rules, the algorithm identified 1 rule which is not there in the inheritance path.

Below rules Apply to class is not there in the ancestor tree of the referenced rule.

4

TP-Training-Work-Complaints

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 




after removing the disqualified rule we have 8 rules in the list as shown below.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

4

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

5

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

6

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

7

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

8

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 























5. Rank remaining rule candidates.

In this step, the algorithm uses a sub-process to rank the remaining candidates by using below three steps.
Ranking rules
          A. Sort the remaining rule candidates.
  B. Remove rule candidates with an Availability set to Withdrawn
  C. Determine default rule candidate.

A.Sort the remaining rule candidates.

In this step, the algorithm sorts the remaining rules in this specific order.
  • Class
  • Ruleset
  • Circumstance
  • Circumstance Date
  • Data/time Range
  • Version

Class - If the Apply to a class of the rule from the remaining list is closer to the referenced rule's apply to class then it will be ranked higher.

Ruleset - Within each class, rules are sorted according to the operator's ruleset stack.

Circumstance, Circumstance Date, and Date/time range - are used as qualifiers to further refine the rules.

Version - Lastly rules are sorted with the ruleset versions to ensure circumstanced rules are not overridden if the base rule is updated recently.

After considering the above criteria, the algorithm sorts the remaining rules as shown below. Row number 4 from the above list will come after row number 5.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Withdrawn

ServiceRequest

02-01-10

 

2

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

3

TP-Training-Work-ServiceRequest

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

4

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

5

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

6

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

7

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

8

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 
























B. Remove rule candidates with an Availability set to Withdrawn

Once we have the sorting order, the algorithm removes the rules where availability is withdrawn.

If the rule availability is "Withdrawn" indicates that the Withdrawn version and below (lower) versions of the same rule (same rule type, name, and class) will not be selected during the rule resolution process.

From the above list, rule (row number 1) in 02-01-10 is Withdrawn, so the current version and lower versions of the same type, name, and class will be removed. In this example row numbers, 1,2, and 3 are removed from the list.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

2

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

3

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 

4

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-01

 

5

TP

Rule-HTML-Section

AllocateBudget

Available

TP

03-01-01

 
















C. Determine default rule candidate.

In this last step of the ranking process, the algorithm determines the default rule.

The default rule is the first rule from the list without any qualifiers (any circumstances). After identifying the default rule, the algorithm removes the rules below the Default rule from the list.

In this example, Row number 3 which is there in ServiceRequest:02-01-05 is the default rule and row numbers 4 and 5 will be removed from the list.

S.No

Apply to class

Rule type

Rule name

Availability

Ruleset

Version

Qualifier

1

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Circumstance)

2

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

Yes (Date)

3

TP-Training-Work

Rule-HTML-Section

AllocateBudget

Available

ServiceRequest

02-01-05

 











6. Set the rules cache

After the Ranking process has been done, the algorithm sets the remaining rules into the rules cache. In this scenario, finally, we have 3 rules in the rules cache.

Algorithm successfully Populated rules cache, now algorithm uses below steps to finalize the rule, select and execute from the rules cache (already explained above as part of Rule instances are found in the Rules cache).

  1. Find rule in the rules cache
  2. Find the best instance and check for duplicates
  3. Confirm the rule is available for use (Availability is not set to Block).
  4. Verify the user is authorized to use the rule

Happy Learning 😃 Share with others. Sharing is Learning 😄



6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Glad..it helped you. Hope you will like other posts as well. Share with others.

      Delete
  2. Thanks for the detailed explanation. Kudos to your team for the great effort.

    ReplyDelete
  3. Thanks a lot for such a clear explanations

    ReplyDelete
  4. Thank you so much for sharing valuable knowledge

    ReplyDelete