Reputation: 23
Most of the single page browser application are supposed to be "collaborative" which means that several people can edit the same document or object simultaneously (think about google docs). I'm trying to implement a collaborative application using Backbone.js and Rails on backend. I do understand how Backbone model sync works, but I wonder what is the best practice to handle conflicts resolution?
This is an example: a user updates field "author" of a book and Backbone.js model "Book" sends sync request to server... but someone else already updated this field this this book just a second ago. How to handle this situation? Is there any common practices / frameworks / libraries to handle conflicts?
Upvotes: 2
Views: 200
Reputation: 4583
Sign the data to confirm its validity:
Creation of a record on the back-end:
{
"author": "Ernest Hemingway",
"signature": "8332164f91b31973fe482b82a78b3b49"
}
Then when somebody retrieves the record, the signature is retrieved along. When he edits the record the signature is sent back to the back-end. If the signature matches with what is in the DB, it's a valid edit and the back-end generates a new signature for the record and saves it. If the signature does not match it means somebody else did an edit in the mean-time.
Upvotes: 1