Fluent Commerce Logo
Docs

Concurrency Concerns

Essential knowledge

Changed on:

17 Apr 2025

Overview

This articles illustrated different case scenarios where concurrency can happen when updating fulfilment attributes, and how it can be addressed. 

Key points

  • Concurrency happens when 2 processes update the same attribute at the same time 
  • Concurrency can result in data loss 
  • Concurrency can be solved by event queue management or code changes

Purchase Orders (POs)

Concern with updating fulfilment attributes (PO is one large single json attribute) - 2 processes updating the same attribute at the same time can result is data loss 3  examples where concurrency can be an issue:
  • "deliveredQuantity" in UpdateDeliveredQtyForPOInvoice.java
  • "invoicedQuantity" in UpdateInvoicedQtyForPOInvoice.java
  • "InvoicedQty" in UpdateInvoicedQtyAttribute.java
 Code patterns like this: Thread 1: Loads existing attribute => array ([ 1 ])Thread 2: Loads existing attribute => same array ([ 1 ])Thread 1: Add item(s) to array => [ 1, 2 ]Thread 2: Add item(s) to array => [ 1, 3 ]Thread 1: Save array => [ 1, 2 ]Thread 2: Save array => [ 1, 3 ] Value will be [1, 3] in attribute after both threads are done.Where it should be [1, 2, 3]. So the problem occurs if thread 2 loads the existing attribute before thread one has completed.If something happens to an attribute while the thread is manipulating its value, the thread will overwrite whatever change happened between loading the attribute and saving it.

Order Item Line Number

GenerateOrderItemLineNumber - possible concurrency issue generating order line numbers

Possible Solutions

  • See if there is any scope to break data mapping down to individual attributes in some key places (instead of grouped JSON attributes) to avoid such scenarios
  • Reduce number of events that could cause a clash - e.g. remove PO confirmation and rely on invoice only?
  • Manage message queue order (e.g. using queue ID) to send messages to one at a time Fluent in correct order, but Fluent would need to respond each time
  • Manage consolidation of multiple events to same PO externally to Fluent, to send in a single update at a time - have an external service and queue that only updates the Fluent PO attribute once