A note from 2026: This article was published in 2016. The “hybris” product name has since been phased out in favor of SAP Commerce Cloud, and several recommendations should be reviewed for modern projects: Netflix Hystrix has been in maintenance mode since 2018, and Resilience4j, Spring Cloud Circuit Breaker, or platform-level resilience policies are now more common choices.

Introduction

Inventory management is one of the challenging topics in e-commerce. As part of my research, I came up with some best practices in this area.

In this article, you can find information about inaccurate inventory records and inventory balance discrepancies, as well as techniques to compensate for inventory record errors and stock update delays.

I explain the details of inventory data importing: integration interfaces, guaranteed data delivery, failover and error handling, and mass update specifics. I am going to go over the architecture of lean stock updates that could be useful for marketplaces with millions of products and distributed warehouses.

You will find details about data anomalies and how to process products with multiple product units, use stock history, and implement rule-based product availability. I will also cover a large topic: stock management for different types of product bundles.

Inaccurate inventory records

This is an all-too-common problem when inventory data is not accurate. Outdated, damaged, or spoiled inventory, wrong labels, lost items, delayed stock updates, and other inventory-related issues occur everywhere. Inaccuracy takes shape in many forms, such as inaccurate quantities, inaccurate storage locations, inaccurate pricing, and inaccurate identification. This happens very often with retail companies, especially big-box retailers that have millions of SKUs.

There are various techniques you can use to compensate for inventory record errors. Two of them are widely used in e-commerce:

Stock decrement diagram

Manual double-check stock verification process

Product variants

Sometimes the same product is available in different styles or types. From the ERP standpoint, these are different items. For customers, all of them are different versions of the same product.

Hybris requires linking product variants with each other. There is a base product and optional variant products that have an attribute pointing to their base product. In some ERP systems, this grouping is achieved through product categories or the SKU pattern.

Sometimes the WMS knows nothing about variants. For example, cheap rubber bracelets may come in various colors with the same SKU. It is not a problem for traditional retail: the customer picks the right color, and there is no need to have separate SKUs in the WMS. However, for an e-commerce website, you may want to ask the customer about the color. How will you push this information to the warehouse once the order is placed? In comments? How do you determine the stock level for each color? These questions should be asked.

Merging and splitting products

Merging and splitting products stock diagram

Another pattern is based on the concept of backup suppliers. These warehouses should be 100% reliable in terms of product availability, but at the cost of a higher price for the seller.

Backup suppliers stock diagram

Using a backup supplier is certainly a red flag for the procurement department.

The last example of merging products is typical for furniture:

Furniture product merging stock diagram

The same approach is used for bundles that are available when all components are available.

Inventory balance discrepancy

The e-commerce website is not the only consumer of WMS data. Other systems may update the information in it, and the changes may propagate with some delay. Certainly, you need to minimize this delay. However, for various reasons, this delay can be long enough to create issues with stock inaccuracy.

There are two main types of delays:

Inventory balance discrepancy diagram

In the example below, “Warehouse reserve” is an inbound queue, and “hybris reserved” is an outbound queue.

The inbound queue (warehouse reserve) is tightly linked with the order management processes in WMS. Usually, it takes some time to process the update. It might be a technical delay or a workflow that comprises a set of steps for validating the order and processing the reserves. The initial state of the stock is 500 items.

Order management stock reserve example for order 1

As we can see, three items are still being processed on the WMS side, and another three items were reserved by hybris. We initially had 500 items, and 10 items were sold, but at this moment the hybris stock level service shows 497 items. This value is more than the real stock has.

This is a reason why you need to send a synchronization request to WMS from the shopping cart. However, the warehouse shows 494, which is also more than 490. In order to mitigate the discrepancy, you need to use WMS unprocessed requests in the hybris availability calculation.

hybrisRealtimeAvailabilityCheck(t) is mainly used in the shopping cart and checkout process. hybrisProductAvailability is mainly used for Solr indexing and product pages.

Let’s place another order, #2. There are two products in it.

Order management stock reserve example for order 2

If we accept the order for 494 or 489 products, we won’t be able to fulfill the order because the stock has only 488 items.

Order management stock reserve example for order 3

Order management remaining stock example

To summarize, you need two interfaces to your WMS service:

Integration details

Hybris default integration diagram

Default hybris stock integration diagram

This diagram shows the stock-related processes only. Exporting orders is not shown here, nor are fulfillment-related processes.

Key integration interfaces

Async integration endpoints

Sync integration endpoints

Guaranteed delivery

All asynchronous communication from and to hybris should flow through an Enterprise Message Bus. It is important to make messages persistent so that they are not lost even if the messaging system crashes.

All synchronous communication from and to hybris is recommended to flow through an API Gateway. Using a unified gateway for all API calls will allow you to monitor throughput and test API usage.

Failover and graceful error handling

I recommend using Netflix Hystrix to manage failures in the data exchange. This framework uses the circuit breaker pattern, which will stop further requests if a configurable number of requests starts to fail. This will ensure that the app servers are not endlessly hung up, allowing for graceful error handling.

Mass update with ImpEx

If you need to update large numbers of items using ImpEx, I recommend taking the following into account:

For example:

INSERT_UPDATE StockLevel;available;warehouse(code)[unique=true];inStockStatus(code);productCode[unique=true]
...

For this example, let’s check the indexes for the following lookup attributes:

If you don’t have a significant number of warehouses, reading sequentially is faster than working through an index. Let’s look at the OOTB hybris configuration:

Lean stock update

According to this concept, the WMS updates Solr rather than hybris. Solr updates the hybris database. Some events may force this update. It will reduce the database load significantly.

I used this concept in my hybris Marketplace PoC.

Lean stock update architecture diagram

Incremental updates

Very often, the external product stock data provider, such as ERP or WMS, is a bottleneck for data exchange. Pulling all data is too expensive and slow. Incremental updates allow you to make this process more efficient by transferring changed data only. As a rule, something like a last modified time attribute is available in the source system. Using this attribute as a filter will significantly reduce server load and increase performance.

Solr and caching

I encourage you to have a look at my article about the hybris Marketplace. I used a set of 2M products, 16K categories, and 6000 facets. The numbers are too large to be used with conventional hybris. It became possible to use these with hybris only because all data is in the fast document-oriented Solr database rather than a relatively slow relational database. Availability information is also in Solr. In another PoC, I demonstrated that it takes seconds to update availability information for a large number of products, warehouses, and even customer groups.

Data anomalies

There are three types of anomalies: update, deletion, and insertion anomalies.

Updates

An update anomaly is a data inconsistency that results from data redundancy and a partial update.

Normally, there should not be any update anomalies if the system is designed properly. See the Inserts section below as well.

Deletes

A deletion anomaly is the unintended loss of data due to deletion of other data. Don’t remove objects if you want to avoid data inconsistency. Use special statuses to mark items as non-relevant.

Inserts

An insertion anomaly is the inability to add data to the database due to the absence of other data.

For our topic, there is a common issue related to insertion anomaly, as follows:

As a result, the stock update may end up with errors. It is clear that these situations should be planned well beforehand. Certainly, you need to insert stock level items only if all referencing objects are in place. However, you need to check it for each StockLevel item imported from WMS, which is not good for performance.

I recommend preprocessing the incoming data and splitting it into two parts: update and insert. Products and warehouses should be cached in memory to make preprocessing faster. The StockLevel items that were sorted out for insertion should be processed if all referenced components are found: product number and warehouse.

Historical data

Think about collecting historical data for all availability data updates in external NoSQL storage. It is a good source for further big data processing to implement such features as:

Also, the collected information is great for troubleshooting.

Bundles

There are four different types of bundles in hybris:

hybris product catalog ERP
Type 1. Fully virtual no bundle SKU no bundle SKU
Type 2. ERP product grouping no bundle SKU bundle SKU is present
Type 3. Hybris product grouping bundle SKU is present no bundle SKU
Type 4. Bundles are regular products bundle SKU is present bundle SKU is present

Type 1. Fully virtual

ERP is not aware of bundles, only of bundle components. Hybris does not have bundles in the product catalog.

Fully virtual bundle stock model

Example: Build your PC product configurator:

Build your PC product configurator screenshot

For this option, the availability of the bundle is based on the availability of bundle components. This option is used when the bundles are supposed to be built individually for customers based on their selection.

Type 2. ERP product grouping

Like the previous option, hybris is not aware of bundles. However, ERP has bundles as separate SKUs. This pattern is common in situations where ERP has SKUs for all possible combinations of components generated by a hybris-powered product builder, like the one shown above. Unlike the previous option, the bundles are stock-keeping units on the ERP/WMS side. If some bundles are unavailable, you will not be able to order them. In this option, real-time availability requests are essential because there is no way to store information about bundle availability in hybris. This pattern is good for systems where ERP bundles are virtual and the absolute number of possible bundles is huge. Otherwise, it is recommended to go with Type 4. ERP calculates bundle availability dynamically, by request, according to some algorithm known to ERP/WMS.

ERP product grouping bundle stock model

Type 3. Hybris product grouping

In this option, ERP is not aware of bundles. Bundles exist in hybris only. Bundle availability depends on information from ERP/WMS at the component level and from hybris at the component and bundle levels.

Hybris product grouping bundle stock model

Type 4. Bundles are regular products

In this option, bundles exist both in ERP/WMS and hybris. Each bundle is a purchasable item with a separate SKU. The set of components of the bundle is just for reference; the availability information is based on ERP/WMS data for the bundle SKU.

Regular product bundle stock model

Monitoring

Collecting historical data is great for system health monitoring. If you update your stock every day or every hour, you can create and continuously update a typical pattern of a single update or a group of sequential updates. Any deviations from these patterns can be flagged as real-time alerts to admins.

It is also a very useful tool for early identification of issues related to data exchange.

Multiple units

In some cases, handling products in different units of measure is necessary. For example, if you buy products in a country where the metric system is used and sell them in a country where the imperial system is used, you will need to convert the units.

Warehouse units and purchase units can be different.

For furniture, a kitchen set can consist of several components. Some of these components are purchasable separately, but some of them can be sold only as part of other units. In addition to that, some components are common for different kitchen sets. How do you determine the number of available kitchen sets by the known number and types of components?

For the last example, in ERP we deal with coils, but for the end customer, two different types of products are available:

These products share the same stock items. From the customer’s perspective, these products are basically variants of one product, “wire”. In addition to that, there is one more challenge: you can’t connect two cuts to have a new longer cut. So there is no easy way to calculate the available stock for such products. If you have 100 feet of wire and your customer wants 90, you will possibly have difficulties with the remaining 10-foot cut. However, that is a topic for a separate article.

Another example of products with multiple units is soap. Soap products can be sold in bars or by weight. When soap is sold in bulk, the customer is asked about the weight of the piece. The same situation occurs with liquids and granular materials, which are common for construction material B2B e-commerce websites.

Rule-based product availability

Sometimes product availability should depend on a combination of many factors:

Availability = Function(RawStockData, CL, CS, PA, PPA, PM, DM)

The best way to implement product availability rules is to use Drools, included in hybris 6.x. RawStockData can be wrapped into Drools Globals methods. The remaining listed components can be implemented as Drools Facts. There are different ways to write rules. The hybris rule builder can be leveraged for this purpose as well. The results can also be cached for faster lookup.

© Rauf Aliev, October 2016