i have a scenario where i have to make available a document for viewing and editing to multiple users, the users can edit and view the document at the same time. Now the problem arises here if for example user A and user B are viewing a document at the same time and if both the user change the state of the document and user A saves it at x instant of time and user B saves it at y instant of time where y>z in the time dimension. The changes by the user A will be overridden by changes made by the user B.
Possible solutions that i have in mind
(1) i’ll keep a bit e.g. isViewedCurrently and only allow a single user to view/edit the document,
(2) save changes of every user separately and then appoint a role who will merge those
changes (impractical)
please suggest some solution that i can implement, can anyone explain how google does it, the google docs are shared, viewed and edit by multiple users and changes of each user is persisted.
im using SQL server 2008 R2 for persisting the application data.
EDIT:
google has implemented an editing surface from scratch and that too in JavaScript
http://googledocs.blogspot.com/2010/05/whats-different-about-new-google-docs.html#!/2010/05/whats-different-about-new-google-docs.html
http://googledocs.blogspot.com/2010/05/whats-different-about-new-google-docs.html#!/2010/05/whats-different-about-new-google-docs.html
The solution that springs to my mind is like this:
- Store the document in a version control system
- When viewing, the user gets the latest version as of that moment
- When saving, a new version gets created. If the VCS changes have been committed in the meantime, an automatic merge is attempted.
- If the merge fails, the user is alerted that conflicting changes have been made and is asked to resolve the conflicts.
- If the merge succeeds, the merged version is stored.
This assumes that the document is stored in a format that allows comparissons and merges.
1