Skip to main content

Stock real time updates

Proposal

Below shows our proposal for the stock updates. Currently NAV send stock updates to Hybris each 10 minutes. Those updates will also be sent to Algolia to keep the indices up to date as much as possible.

Since in Algolia there are only products with stock, it is necessary to obtain those products that no longer have stock after the update sent by NAV. Products in Algolia are indexed at the style level so we can have two situations:

  1. The style is out of stock in any size: the style should be removed from Algolia and the other styles with stock should be updated to remove the reference of the out of stock style from their variants array.
  2. A size is out of stock: the style needs to be updated to remove the size from its sizes array

To delete a style from Algolia we need to use the deleteObjects method.

To update variants or sizes arrays in a style we need to use the saveObjects method because updating nested attributes is not possible using partialUpdateObjects. In order to not delete the rest of the data in the index we need to call first the getObjects method

Architecture

Below is a proposed flow:

Stock real time updates Flow

Flow

  1. When a stock update coming from NAV is processed successfully in Hybris, Hybris sends a HTTP request to a REST endpoint in the Hybris API Gateway. This is POST: product/stock
  2. This sends an event to EventBridge
  3. The Event is picked up by the Product Event Bus in the Platform Domain.
  4. There is a rule which triggers a lambda in the Algolia domain which:
  5. Gets the JSON from the EventBridge event
  6. Calls Algolia using saveObjects or deleteObjects, depending on the stock status on each product being updated

Resources