How to prevent “Edit conflict”.

Hello there,

My question is regarding the best way to prevent “Edit conflict” in backendless data tables.

The scenario is like this:

    My users have credit points to download some material. By one API call I check the credit amount, already stored in the database. Make the material available to download and reduce one point from the credit I already read from the response. I update the new credit (post/put) to the database.
The problem is aroused when two or more simultaneous requests is sent to the backendless by the same user. Because all of those requests return the same amount of initial credit and I have to calculate the new points just based on the credit amount I got from the step 2.

What do you suggest? I’m using the REST API.

P.S: [Although it may seen somehow off-topic, but as I searched the support forum but couldn’t the similar situation, the answer may be helpful in other cases]

Hi Al,

try to use Atomic Counter API for your case.

This API is intended for resolving concurrent client requests and provides a centralized server-side facility for working with values that may be updated atomically. Every counter has a name assigned to it. The name is used in all operations to identify the counter. Since the counter value is managed centrally, multiple heterogeneous clients can access and modify the value.

If you have any further questions that you cannot find the answer in documentation, please do not hesitate to ask us in this thread.