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.
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.
Taking the example of the rules engine in EdgeOne, the working process of a rules engine can be summarized in the following steps:
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.
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.
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.
The conditions that can be configured in EdgeOne's rules engine are listed in the table below for you to refer to.
Type | Description | Sample values |
---|---|---|
HOST | Request Host | www.example.com |
URL Path | Request URL path | If 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 Full | Complete the content of the requested URL | https://www.example.com/foo |
Query string | Query string in the request URL | Parameter name: key parameter value: value |
File extension | File extension (file extension) of the request content | jpg, png, CSS |
File name | File name of the requested content | foo.txt |
HTTP request header | HTTP request header | HTTP request header name: name HTTP request header value: value |
Client geolocation | Country/region of the client IP | United States |
Request protocol | Requested protocol type | HTTPS or HTTP |
All | Any site request | N/A |
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.
Action | Description | Supported 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 TTL | By 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 TTL | You 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 Prefresh | Cached resources are validated via origin-pull before expiration so that your site can respond to requests more rapidly. | HOSTURL FULLURL PathFile nameFile extension |
Offline Cache | After 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 |
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.
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.