Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
one day i'llwrite my own editor like the google one, till then im gonna stick to a solution more or less like you have suggested... –  dakait Feb 18 '13 at 3:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.