<p>What algorithms and processes are involved in storing revision changes like stackoverflow and wikipedia do?</p>

<p>Is only one copy of the message kept? And if so is it only the latest copy?  Then only changes to go back to the previous version(s) are stored from there?   (This would make for a faster display of the main message).
Or are complete messages stored? And if so is the compare done between these on each display?</p>

<p>What algorithms are best used to determine the exact changes in the message?  How is this data stored in a database?</p>

<p>If anyone knows exactly what wikipedia or stackoverlfow does I'd love to know.</p>

[{'answer_id': 80151, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 1, 'selected': False, 'text': '<p>Usually messages are stored as complete snapshots. Previous versions are disabled, and the most recent is displayed. There may be optimizations used like caching which version is the most recent.</p>\n'}, {'answer_id': 80179, 'author': 'Thomas', 'author_id': 14637, 'author_profile': 'https://Stackoverflow.com/users/14637', 'pm_score': 2, 'selected': True, 'text': '<p>The <a href="http://en.wikipedia.org/wiki/Diff#Algorithm" rel="nofollow noreferrer">longest common substring algorithm</a> can be used to detect differences between versions, but it is limited. For example, it does not detect the moving around of text as such, but it would see this as unrelated removals and insertions.</p>\n\n<p>I suppose that websites normally store the latest copy in full, and apply reverse diffs from there. This is also the way <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System" rel="nofollow noreferrer">CVS</a> works, but <a href="http://en.wikipedia.org/wiki/Subversion_(software)" rel="nofollow noreferrer">Subversion</a> uses forward diffs, which results in slower checkouts.</p>\n\n<p>To store this in a database, one could maintain a main table with the latest versions, and have a separate table with the reverse differences. This table would have rows in the format <code>(article_id, revision_id, differences)</code>.</p>\n'}, {'answer_id': 80196, 'author': 'mattlant', 'author_id': 14642, 'author_profile': 'https://Stackoverflow.com/users/14642', 'pm_score': 0, 'selected': False, 'text': '<p>Typical revision changes are stored using a delta algorithm, so the only data stored are the changes in each revision in relation to the original. I am unsure of wikipedia or stackoverflow how they have it implemented.</p>\n'}, {'answer_id': 80849, 'author': 'Davy Landman', 'author_id': 11098, 'author_profile': 'https://Stackoverflow.com/users/11098', 'pm_score': 0, 'selected': False, 'text': '<p>I would use the following technique:</p>\n\n<ul>\n<li>Store the current message as complete text. </li>\n<li>Store the history using the delta algorithm.</li>\n</ul>\n\n<p>This will keep your performance good with regular display, while keeping the storage to a minimum for the history.</p>\n'}, {'answer_id': 81844, 'author': 'Erik Johansson', 'author_id': 15307, 'author_profile': 'https://Stackoverflow.com/users/15307', 'pm_score': 2, 'selected': False, 'text': '<p>Mediawiki (the sotware for wikipedia) stores full text for all revision see the <a href="http://www.mediawiki.org/wiki/Image:Mediawiki-database-schema.png" rel="nofollow noreferrer">database schema</a>. Each entry in the <a href="http://www.mediawiki.org/wiki/Text_table" rel="nofollow noreferrer">text table</a> in Mediawiki has flags that tells if the content has been e.g. gziped, using a standard compression is often  the sanest option.</p>\n\n<p>I can\'t tell you how to do the diffs algorithmically, but what ever algorithm you use you should do it from two full versions of the text. That is fetch the complete version of old and new object from database then do the diff. This makes it possible to easily change the diffing algorithm. </p>\n\n<p><a href="http://git.or.cz/" rel="nofollow noreferrer">Git</a> is a great example of a Unix application that can do very cheap (storage and speedwise) delta storage. There are wikis that can use git e.g. <a href="http://ikiwiki.info/" rel="nofollow noreferrer">ikiwiki</a>, but I\'m guessing you want to do it with a database.</p>\n'}]
['https://Stackoverflow.com/questions/80141', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3153/']