I am working on designing a collaborative system where multiple users can edit the same document, much like googledocs, and I guess ‘search suggestions’, but in no way as advanced.
My question is this, will my design work? I know enough php/ajax to design this, using jQuery for the ajax part. But I have never made such a system, and therefore the design may have huge flaws.
The editable part of the webpage is a table, where certain cells can be edited (again much like google docs spreadsheets).
In theory this will work, whenever a tables cell is changed, the changes are stored in a history, and every 1000ms (after the last post returned successfully) I post the cell changes to a server
Simultaneously, another ajax function polls the server (also every 1000ms after the last call return successfull) and asks for a list of changes done to all the cells.
Is this the simple way of how google does it?
This is a debatable subject and most solutions depend on requirements and use cases rather than what’s “correct”. One of the more complex solutions is to use Semaphore:
http://en.wikipedia.org/wiki/Semaphore_(programming)
The railroad semaphore flag:
http://en.wikipedia.org/wiki/Railway_semaphore_signal
That said, in your case, I suspect the “last value written” should be used. Simply have every edit queued on the server and then applied to it’s cell. Obviously, there will be cases where data is inappropriately overwritten, but that’s where human’s come into play.
You could choose to detect when two users have focused and are editing the same cell — when this occurs, send a notice to each use that their changes may conflict with another user. The least-aggressive user will back off and go do something else. Obviously there are more cases such as mass-edits but again, this all depends on your requirements.