A note from 2026: This article was published in 2016. SAP hybris is now SAP Commerce Cloud, and the specific components listed here—WildFly 10.1, KIE Server 7.0.0.Beta2, and Drools Workbench 7.0.0.Beta2—are obsolete; use currently supported SAP Commerce Cloud and Drools/KIE versions when applying this architecture.

Introduction

In this post, I would like to introduce the first results of Drools Fusion and hybris integration. Based on this approach, you can create comprehensive, cost-competitive, and scalable e-commerce solutions for tasks such as real-time personalization and customer segmentation, monitoring, and lean data processing.

Let’s take “Personalization,” for instance. The hybris personalization module performs customer behavior analysis on the same servers and during the web request.

Personalization processing flow in hybris

As you can see, these steps are sequential. It is no secret that the personalization capabilities in hybris always slow down the system, sometimes by up to 1.5–2 times. The typical solution is to add more CPU and memory resources, but it has the same limited effect as optimizing the code and the database. Most often, the personalization features are not used at all.

I sought to create a prototype of a very scalable and cost-efficient solution, and eventually I created a PoC.

Solution

The solution explained in this article allows you to create customer behavior-driven e-commerce websites without any significant impact on performance. The key components of the solution are the following:

There are also key concepts that make the solution unique:

Complex event processing architecture with hybris and Drools Fusion

In the video below, you will see a simple demonstration of the concept. There are two sample rules in the example:

  1. When the customer visits more than 5 webpages marked as “Photo” during the last 30 seconds, then this customer is a photographer.
  2. When the customer visits more than 5 webpages marked as “Non-Photo” during the last 30 seconds, then this customer is a non-photographer.

In this simple example, a page is marked as Photo if the page URL contains the keyword “camera.” Otherwise, this page is marked as “Non-photo.”

Also, to make things simpler, when I say “customer,” I mean “customer session.”

Step 1. The hybris storefront creates an event. When a customer requests the page, the hybris storefront sends an event, “TransactionEvent.” In our example, the event structure is super simple: session ID and pageCategory (Photo/non-photo). It is a very fast operation because hybris doesn’t care about message delivery. It simply throws the message into the queue.

Step 2. The message is inserted into Drools Fusion working memory. It happens milliseconds after the message is thrown by the hybris storefront. Message processing is a bit slower, but it is also a pretty fast operation because only one Drools Fusion command is performed: “insert an event.” The event is pulled from the queue and created in memory. At this point, the rule starts working. It is important that there is no process waiting for the system to return with any processing results. The message was simply thrown from the queue to Drools Fusion.

In the example, the event is configured to live for the next 30 seconds. After that, the event will be purged automatically.

Step 2.1. hybris can provide Drools Fusion with some data used in the rules, such as customer profile information or session information. There was no need for it in my PoC. This part is very simple and very similar to what is explained in the “Step 2” section, with one exception: hybris pushes facts rather than events. Perhaps it uses the same interfaces and approach as for events.

Step 3. Drools Fusion processes the events/facts stored in working memory. There is a rule that triggers when the customer has visited 5 photo-related pages within the last 30 seconds.

There are two parts of the Drools rule: LHS (left-hand side) and RHS (right-hand side). LHS is the “when” part, a set of conditions. There are three conditions in the rule:

Drools rule conditions in the Workbench

As a result, the session state is changed. There are different ways to implement the “then” part of the rule. I set up a new state for the session that is created in working memory (there is another rule for that). The object in working memory is updated.

It is important that Drools Fusion works in STREAM mode in this example. Events are time-ordered, and old expired events are removed automatically.

Step 4. hybris requests the status of the session and updates its internal state. Drools Fusion is able to push this information back to hybris instead of waiting for the hybris data request, but in my example I used the simplest approach.

Performance

CEP engines are designed to process a large volume of events at extremely high speeds. Throughput requirements are often well over 100,000 events per second, while processing latency demands can be as low as one millisecond or less.

Due to its asynchronous nature, the system is very scalable. The hybris part likely does not require scaling at all because this solution doesn’t have any “heavy” components inside hybris.

Components

Video

© Rauf Aliev, October 2016