AnsweredAssumed Answered

How to handle potential race conditions in AGOL hosted feature layer

Question asked by tom.rippetoe on Mar 23, 2018
Latest reply on Mar 29, 2018 by tom.rippetoe

I have an AGOL hosted feature layer. I have a  'count' field that i want users to be able to update via the REST API applyEdits() method. Because multiple users could be updating the count at the same time, theres a good likelihood that 'race conditions' could exist.... one user could overwrite another users update with an invalid count. 


For example User A and User B are working with the same object at the same time and try to increment the current count, say 15, by 1.  The abbreviated JSON sent to the applyEdits endpoint might look like this: 


"objectid" : 456,

"count" : 16


The request which arrives second should be setting the count to 17 to reflect the actual count, but instead it will set the value incorrectly to 16.


If i was using a SQL update, i could do something like

count = count + 1

That would handle the race conditions because it always adds one to the true current count. 


Is there a way to handle this type of situation via the REST API in an AGOL hosted feature layer?