Many types of apps—spreadsheets, writing tools, design tools—could benefit from version control features like history, branching, and diffing. But common databases (like PostgreSQL, IndexedDB, or Core Data) offer a model focused only on a current snapshot of the user’s data, with little or no knowlege of history.
On Patchwork, we’ve been able to prototype very rapidly because we’re building on top of Automerge, a JSON data storage and synchronization library developed here at Ink & Switch.
Automerge was designed to support local-first software and uses a CRDT sync algorithm to merge together edits made on different devices, without the need for a central authority server. This internal machinery is also a good fit for version control interfaces:
- History: Automerge never deletes anything. It stores every change made to a document with efficient compression. This enables features like dynamic history that rely on a complete log of changes.
- Diffs: Automerge can compute an exact difference between two points in history of a document. It doesn’t need to resort to heuristics because the full edit history is tracked. This enables features like diff visualizations. For text in particular, Automerge gives each character has its own ID, so it’s easy to show precisely which characters were deleted or inserted.
- Branching and merging: Automerge supports cloning documents and then merging them back together in reasonable ways using the CRDT algorithm, even if there have been concurrent edits on both copies. This is the underlying capability that supports our simple branching.
It isn’t an accident that Automerge is a good fit for this domain: part of the project vision has always been supporting better versioning tools for collaborative work. It’s noteworthy how much alignment there is between the tools needed to support concurrent offline editing and version control tools—both require tracking history and support for concurrent editing.
In addition to using Automerge’s capabilities for rapid prototyping, part of the goal of Patchwork is to motivate future improvements to Automerge. We’ve tried improvements like attributing changes to authors in diffs, which was instrumental to our Edit Groups prototype. Then we’re working with the Automerge team on upstream changes to more deeply support user-facing version control features.