Concurrent json document access

0 votes
How does app42 service reacts if multiple users try to read/write same document. As an example, suppose that I have a document which has a key/value pair like "number_of_registered_users":"x", and every time a new user is being registered, he first reads "number_of_registered_users", then increments it and then writes back to document. What happens if
 

User1, reads "number_of_registered_users" as 1

User2, reads "number_of_registered_users" as 1

User1, increments 1 and writes back "number_of_registered_users" as 2

User2, increments 1 and writes back "number_of_registered_users" as 2, however he should have written it as 3.

 

p.s

The functionality that I'm trying to implement is when I'm registering a new user (not using the users api, but using storage api) through custom code, I want to return back the name of the user in the following format "user"+registed_users_count (ie user223).
asked Oct 15, 2014 in App42 Cloud API-BaaS by vladislav (10 points)
edited Oct 15, 2014 by vladislav

1 Answer

0 votes

Hello Vladislav,

Get and Update on storage keys are not thread safe and you may experience inconsistency in case of concurrency.

To show the number of user registration based on his arrival, you can maintain the time of registration in milliseconds in the leaderbaord as his score. To check the position, you can ask for ranking using ascending filter. This will give ranking of user that you can use as registered number.

Let me know if it makes sense.

Himanshu Sharma

answered Oct 16, 2014 by hs00105 (2,005 points)
I hope your query has been resolved, kindly let us know if you have more questions for us.
Thanks,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...