简体   繁体   中英

How to store documents like google docs?

I'm interested how does google docs store documents on server side because I need to create similar application.

Does it use pure RTF/ODF files or own database? How do they make possible versioning and undo/redo feature?

If anybody have knowing according this question please share with me.

To answer you question specifically to how Google Docs works. They use a technology called

Operational Transformation

You may be able to use one of operational transformation engines listed on: https://en.wikipedia.org/wiki/Operational_transform#OT_software

The basic idea is that every operation has a context, eg "delete the fourth word in the fifth paragraph" or "add an input box after the button". The clients all send each other operations thru the server. The clients and server each keep their own version of the document and apply operations as they come.

When operations have overlapping contexts, there are a bunch of rules that kick in to resolve conflicts. Like you can't modify something that's been deleted, so the delete must come last in a sequence of concurrent operations on that context.

It's possible that the various clients and server will get out of sync, so you need a secondary algorithm to maintain consistency. One way would be to reload the data from the server whenever a conflict is detected.

--This is an answer I got from a professor when I asked the same thing a couple of years ago.

You should use a database. Perhaps a table storing each document revision. First, find a way to determine whether an update is significant or not. You can store minor changes client side for redo/undo, and then, either periodically or per some condition (eg, user hits save), create a database entry per revision (you can store things like bytes changed, bytes added, bytes deleted, etc.).

Take a look at MediaWiki, which is open source, and essentially does what you're asking (ie, take a look at their tables and code).

RTF/ODF would typically be generated, and served, when a user requests exporting the document.

Possibly, you should consider utilizing Google Drive's public API. See link for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM