educative.io

How concurrency and conflicts will be handled

If two users are trying to upload same chunk number at the same time , modified with different contents then how the conflict will be resolved?
If an offline user made some changes to local chunk and same chunk gets modified by other online user before the first offline user comes online then how syncing will happen after resolving the conflicts?

3 Likes

One way of handling conflict resolution is to only accept one of the changes and reject the other changes and also notify the failed client about the rejection. We can employ the same technique used by the modern databases. Databases typically maintain a version for every record and the version is updated whenever the record is updated. While updating a record, the client/user also provides the current version of the record which they have seen before updating the record. The server only updates the record if the current version provided the client and the version in the datastore are the same. If the version in DB is different from what the client has provided, it means that someone else has updated the record after the user has read the record. In such cases, the database rejects the transaction essentially requiring the user to retry the entire operation again.

A similar strategy can be employed over here as well by versioning the chunks. Each chunk is given some version number whenever it is updated. Only the first request to update the chunks will be accepted and all the subsequent requests can be failed. It will be up to the user to decide what action to take in such cases.

9 Likes