Designing a rule-based reservation system in Salesforce

Chary Lingachary
4 min readAug 7, 2022

There are many rule engines available in the market today. A few are InRule, Drools, JRule, EasyRules, Decisions, and IBM Decision Manager. However, depending on your project, an investment in a rule engine product may not be justifiable. Today, I will describe a method for designing a simple rule-based reservation system in Salesforce. This method may be used for any reservation system.

Rule Engine Architecture

A rule engine architecture at a minimum has the following components.

  • Rule database— rules are stored in a database
  • Rule Configurator — a UI application used to define and configure rules
  • Rule Execution Platform — a runtime for executing rule logic
  • Rule Application — an application that relies on the rule execution platform to run configured rules for the application

Reservation System Architecture

A modern reservation system has a portal, an API gateway, a reservation application, and a backend database among other components.

The reservation system may have membership offered at multiple subscription/membership levels. These subscriptions may be configured as products and/or rules in the rule configurator. There are two applications of rules in this context.

  1. Sales staff use the rule configurator to configure and sell a product ( a membership/subscription)
  2. The reservation portal checks a resource's availability (a table in a restaurant, seat availability on a flight or in a game event, a rental car, or a hotel room, etc.) based on the configured product for a given user/member.

Salesforce Design

Let’s look at how to design this solution in Salesforce. Salesforce has evolved from being a CRM platform to a choice of platform for developing enterprise applications such as a reservation system. Salesforce is very intuitive when it comes to designing an object model and its out-of-box user interface helps us build rules database and the configurator with ease.

  1. Object Model — Design an object model in Salesforce for subscriptions, subscription types, rules, and options. Use Object Manager to define custom object types.

2. Rule Configurator — use App Manager to define a new Lightning App and add custom objects to the lightning app.

3. Class Diagram — A class diagram provides a structural view of the system objects in memory and their associations. The class model for the rule-based engine has a RuleInterface class which the Rule class implements. The RuleInterface has one method execute() which executes the logic associated with the rule. Rule1, Rule2, and Rule3 are the classes that extend the Rule class with a specific rule. The Component class is composed of rules and the Product class is composed of components and/or rules.

4. Rule Engine — Implement a rule engine using Apex classes. The rule engine is responsible for retrieving rule definitions from the rule database and executing the logic in the Rule class.

5. Rule Application Define rule application logic including inputs and outputs based on the type of reservation system being developed. The rule application takes application-specific requests, leverages the rule engine to execute rules associated with the user’s membership/subscription, and returns the expected output.

When a request for resource availability is received, the user’s membership is retrieved along with associated rules. Each rule is executed in a certain order by calling execute() method of the Rule object which retrieves the rule definition from the rule database and its associated conditions. Rules are recursively called until all rules are executed. The outcome of each rule execution is reconciled by the rule application before returning the expected result.

Rule application may be exposed as a REST endpoint and/or embedded within the reservation application.

Conclusion

This simple rule-based reservation system may be implemented on other application development platforms such as J2EE, Spring, or .NET as well.

--

--

Chary Lingachary

Chary Lingachary is an Enterprise Architect and a Digital Evangelist. His focus areas include Smart Integrations and Accelerated Integration Ecosystem.