Answer the question
In order to leave comments, you need to log in
How to synchronize user actions and data in a multi-user system?
Good day!
In the process of developing a multi-user system (frontend + microservice backend), I ran into a misunderstanding of how to properly ensure simultaneous work of users.
The essence of the problem:
- user1 went to the information editing page, selected the info1 item and started editing it,
- at the same time, user2 also selected info1, made a small edit and clicked Save.
- however, user1 does not know anything about the fact that the data was changed by another user, makes his own edits and also presses the Save button.
The situation is further complicated by the fact that sometimes it takes some time to completely save the data, because. they are scattered between microservices located on different servers.
Those. after the user2 clicked Save data, he received a notification that the data will be changed, a task is created to change the data, the version number of the data changes and their saving-synchronization begins.
What should I do in this situation regarding the user user1?
My thoughts:
1 - notify user1 that the data has been changed and ask to wait for the synchronization of the data, then pull up the current data in a new way and then repeat the editing operation.
2 - just create a task to change the data from user1 and place it in the execution queue. As a result, the data entered by user2 will be overwritten. At the same time, user1 will not know that he edited irrelevant data, this seems to be not good.
- perhaps there are other options ...
And please advise what can be read on the algorithms for creating such systems where the following nuances are present:
- more than one user with simultaneous access to the system,
- general data that can be changed by any of the users,
- history operations so that you can find out who changed certain data and when.
Is there a more generic name for such systems?
PS I apologize in advance, I could put the tags of the question incorrectly, tk. I couldn't figure out which one to pick right away.
Answer the question
In order to leave comments, you need to log in
You describe a typical situation when working with databases.
Usually 2 strategies are used:
1. do nothing, the last person to write the data wins. The record, of course, must be atomic, i.e. if 2 users write at the same time, then the data of either the first user or the second should be written as a result, but not something in between.
2. blocking access to change, in this case the described situation simply will not arise.
The same approaches are quite applicable in your case.
Both approaches have their advantages and disadvantages, you need to evaluate your specific situation and choose a more suitable approach.
You described the problems that version control systems solve, for example.
There is also a more beautiful, but 2 orders of magnitude more complicated option - CRDT https://m.habr.com/ru/post/418897/ , I bring it here rather for completeness of answers than as real advice, I do not recommend anyone to use CRDT in sell unnecessarily.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question