T
T
TeslaCtroitel2015-10-31 11:25:58
Database
TeslaCtroitel, 2015-10-31 11:25:58

How to resolve data conflict when multiple users edit data at the same time?

Hello, fellow bearded programmers. I am writing here for myself one project, and now a certain architectural problem has arisen, the solution of which I have not yet found. I do not deny, maybe I searched badly and stupidly, but as it is, it is.
I will describe the essence: there is a certain server and a certain number of clients. The client can accept the data from the server, possibly edit it and send it back. The server can take data from the internal storage (DB) and send this data to clients (perhaps many of them are the same, sharing is present), then receive this data and write it to the database. Well, standard architecture in general. And everything is fine until > 2 clients try to send the same data changed.
Example: there is a cell in the database on the server with the string "Hello, Habr!". Two clients are connected and take away this line from the server. The first client changes the string to "Hello, Habrahabr!", the second to "Hello, Habr and Geektimes!", after which they both send them to the server, where these strings are stored in a conditional temporary table. How can the server figure out what to put in the main cell in the database?
In this case, the information should not be lost. You can, of course, notify the user about the version conflict and leave the difficult choice to him, but then fewer windows and annoying warnings = better.
What ideas does anyone have? I will be grateful.
PS Server - C# under .NET 4.5, then there will be C++11. The client is C# under .NET 4.5 and Java.
PSS Perhaps a solution to a similar problem in Git or MS Word will do? Any information on how it's done?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
v- death, 2015-10-31
@TeslaCtroitel

In a request to the service, send data in the format

{
"text" : "то что редактируете",
"text_update" : "на что редактируете"
}

Then compare text with what's in the database. If it matches, then update the value and return http status 200. If not, then send http status 205 Reset Content (indicates that the document needs to be updated).
Then on the client, see what status the server sent. If 200 then say that everything is fine, the record has been updated. If 205 then say that this data has changed
And to track the change in the line in real time, you can use a web socket

R
Roman Mirilaczvili, 2015-10-31
@2ord

There are optimistic and pessimistic locks.
Database Locking: What it is, Why it Matters and W...
A beginner's guide to database locking and the los...

V
Vladimir Martyanov, 2015-10-31
@vilgeforce

Formulate an algorithm by which the server must decide what to write, implement PROFIT. Only you will not be able to formulate, so this is not a task for the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question