Concurrent users updating the same record and transactions

Dear guys who developed parse, could you tell me how the data saving works there (using MongoDB). I’m planning to use the load balancer attached to the same Mongo. Maybe the questions are more related to the MongoDB, I’m not sure.

Let’s say we have 2 concurrent users editing the same record and they saved it at the same time.

  1. Are updates merged - let’s say one user updated one of the columns and the second user updated the other column of the same record. Is there a chance that DB will save only one update?
    If both updates will always be applied then I have the second question here:
    Is there a chance that returned data from the save object calls of both concurrent users won’t return the final data after both updates?

  2. Is the createdAt column determining the real order of the operations on the DB or there is a chance that data with a lower createdAt will appear in DB later than another record with higher createdAt.

  3. Is there any way to use transactions when we use load balancer and multiple parse servers (few updated records at the same time)?

First, just to clarify, you plan to have the load balancer on top of multiple parse server instances (and not multiple mongodb instances), right? Considering that’s true:

  1. if one user updates only column a and another user updates only column b simultaneously, both data will be saved. First user will not receive the new information of column b and second user will not receive the new information of column a automatically. You will need to re-fetch the data or maybe use live query depending on your use-case.
  2. createdAt is set on Parse Sever (and not database) when a new object is created and it is never changed. There is a chance to have a new record being inserted in MongoDB with a createdAt older than an existing object’s.
  3. You can send a batch of write operations to be performed in a transaction. Also take a look at the increment operation. It is atomic and can help to solve many concurrency problems.
1 Like

Thank you,

that’s a great answer, it’s really important to me to know such details.
Yes, we are using an app load balancer and just one centralized MongoDB.
Could you give me any link on how to apply transactions for a few writes?
I can’t find it in specs.

You can see some teste cases here: parse-server/batch.spec.js at master · parse-community/parse-server · GitHub

1 Like