Limited Time Free!  Sign up for 1TB of data transfer and get free trials of WAF and Bot Management!
Get Started Now 
learning center banner

What is a Rules Engine?

Discover what a rules engine is, how it operates, and its role in automating business decisions. Understand its significance in modern-day systems and the advantages it offers.

A rules engine is a tool used to manage and execute rule-based logic. It is based on a predefined set of rules and automatically performs corresponding actions or decisions based on input data and conditions. Rules can be represented in a condition-action format, where conditions describe specific situations or events, and actions define the operations to be executed when the conditions are met. Multiple rules can exist, each with its own conditions and actions.

Advantages of a Rules Engine

The advantages of a rules engine lie in its flexibility and scalability. Users can easily define and manage complex business rules without modifying the underlying code by using a rules engine. A rules engine also enhances the automation of business processes, reducing manual intervention and improving efficiency and accuracy.

Rules engines find extensive applications in various domains, including business process management, decision support systems, risk assessment, fraud detection, network service assurance, and more. They provide organizations and enterprises with a flexible and configurable way to manage and execute complex business rules.

How Does a Rules Engine Work?

Taking the example of the rules engine in EdgeOne, the working process of a rules engine can be summarized in the following steps:

  1. Rule Definition: Firstly, the rules engine needs to define a set of rules based on specific business requirements. Each rule consists of conditions and actions. Conditions describe specific situations or events, while actions define the operations to be executed when the conditions are met.
  2. Data Input: The rules engine receives input data, which it uses to match against the rules. Input data from user sites can include domain names, IP addresses, file names, etc.
  3. Rule Matching: The rules engine matches the input data against the rules in the rule repository. It checks each rule's conditions individually to determine which rules' conditions match the input data.
  4. Inference and Decision: Once the rules engine finds rules that match the input data, it triggers the corresponding actions. These actions can trigger cache configurations, network optimization, intelligent compression, or other business processes.
  5. Output Result: The rules engine generates corresponding policies, including URL rewriting, modification of HTTP headers, and other domain acceleration functionalities.

A rules engine's working process is typically automated. It can quickly perform rule matching and inference based on a predefined set of rules, covering differentiated scenarios in business requirements.

What is the Rule Engine Design Pattern?

The rule engine design pattern is a software development technique that separates rules from the logic of rule processing, following the single responsibility principle. This design pattern allows for the easy addition of new rules without modifying the rest of the system and adheres to the open/closed principle.

The rule engine design pattern consists of an Evaluator class that iterates through a collection of rules, executes them, evaluates the results, and determines actions to take. These rules implement a simple interface, such as IDiscountRule, with a single responsibility and can be simple or complex as needed. This approach enables better code organization, improved readability, maintainability, and testability, especially when there is a need to replace long if-else or switch statements or when data may match multiple conditions and have multiple processes running against it. The rule engine design pattern is particularly useful when different rule sets need to be applied based on specific conditions, such as the record version or a customer object's properties. By separating rules from the processing logic, developers can easily manage and update rules without impacting the overall system architecture.

Rules Engine in EdgeOne

Compared to internet content delivery acceleration services specifically designed for application layer protocols like HTTP/HTTPS, the rules engine in EdgeOne is particularly suitable for content delivery of websites, online applications, streaming media, and more. The rules engine, through its rich configuration options such as cache optimization, file optimization, network optimization, etc., helps you achieve more customized, efficient, and stable content delivery. This enhances the satisfaction of your business users and strengthens the competitiveness of your website, application, or other online services.

The rules engine suits configurations with differences in matching conditions, such as different subdomains, paths, or file extensions. It also supports basic configurations like caching and HTTPS and additional acceleration features like custom cache keys, URL rewriting, and modification of HTTP headers, catering to your specific business needs.

Supported Matching Types

The conditions that can be configured in EdgeOne's rules engine are listed in the table below for you to refer to.

TypeDescriptionSample values
HOSTRequest Hostwww.example.com
URL PathRequest URL pathIf you need to match the /example/foo/bar Path, you can fill in: /example/foo/bar. If you need to match the /example directory and all files under the directory, you can fill in: /example/*.
URL FullComplete the content of the requested URLhttps://www.example.com/foo
Query stringQuery string in the request URLParameter name: key parameter value: value
File extensionFile extension (file extension) of the request contentjpg, png, CSS
File nameFile name of the requested contentfoo.txt
HTTP request headerHTTP request headerHTTP request header name: name HTTP request header value: value
Client geolocationCountry/region of the client IPUnited States
Request protocolRequested protocol typeHTTPS or HTTP
AllAny site requestN/A

Supported Actions

Actions refer to a series of functional configurations executed within the rules engine when a matching request is hit. The table below shows the rules engine's supported matching types and actions. For more details, please see the Supported Matching Types and Actions.

ActionDescriptionSupported Matching Types
Node Cache TTL By configuring the cache TTL, you can optimize the node cache to improve resource loading and update resources promptly.HOSTURL FULLURL PathFile nameFile extension
Browser Cache TTLBy adjusting the cache period of resources in browsers, you can optimize the browser cache and increase the loading speed of the requested resources.HOSTURL FULLURL PathFile nameFile extensionQuery stringClient geolocation

Custom Cache Key
A cache key can be customized to suit your needs by setting the query string, HTTP header, and URL case to load requested resources faster.HOSTURL FULLURL PathFile nameFile extensionQuery string HTTP Request HeaderClient geolocation
Status Code Cache TTLYou can specify a TTL period for origin response status codes, allowing the node to respond with non-2XX codes directly.HOSTURL FULLURL PathFile nameFile extensionQuery string
Cache PrefreshCached resources are validated via origin-pull before expiration so that your site can respond to requests more rapidly.HOSTURL FULLURL PathFile nameFile extension
Offline CacheAfter offline caching is enabled, when your origin fails and resources cannot be pulled through origin-pull, typically, resources cached on nodes (even expired resources) can be used until the origin recovers.HOSTURL FULLURL PathFile nameFile extensionQuery string HTTP Request HeaderClient geolocation

How to Configure?

Here is a simple example provided for readers to reference.

When the request URL is: https://test.example.com/example/1.jpg, the file is cached for a duration of 10 minutes.

When the request URL is: https://test.example.com/example/1.mp4, the file is not subjected to caching.

When the request URL is: https://test.example.com/video/1.jpg, it does not conform to the stipulated rule.
rules engine configuration

Conclusion

Tencent EdgeOne provides users with more flexibility and granularity in business services. You can customize matching types and apply them to corresponding actions according to your needs. If you would like to learn more, please feel free to contact us anytime.