Rethinking Version Control for Real-Time Collaboration
Git, initially designed by Linus Torvalds to streamline patch submissions for the Linux kernel, has undoubtedly transformed the way software is built and maintained. Its distributed nature, branching model, and powerful features have made it the de facto standard for version control in both open-source and commercial projects alike. However, the traditional workflows and paradigms of Git are rooted in a time when collaboration often meant asynchronous communication and occasional code reviews.
Fast forward to today, where virtually all developers are online, connected, and collaborating in real-time. Enter the question: if all developers are already online, why not rethink version control to embrace real-time collaboration?
CRDTs: A Paradigm Shift for Collaborative Editing
First introduced with Google Wave in 2009, and later implemented in Google Docs, CRDTs have proven their ability to facilitate conflict-free editing in real-time. This technology allows multiple users to work on a single document simultaneously, with automatic conflict resolution. Can we leverage this power for collaborative code development?
Challenge
In traditional development, code is compiled before execution to ensure it adheres to the programming language's syntax and rules. This upfront compilation catches errors early and prevents the code from even running if it's riddled with mistakes.
The problem with real-time collaboration is that multiple developers can be editing the code simultaneously. With each change, the system needs to verify if the entire codebase remains compilable. This becomes a challenge because:
Constant Checks: Verifying compilation after every single keystroke can be computationally expensive and slow down the development process.
Partial Code: As developers type, the code might be in an incomplete state. Checking for compilation errors on incomplete code might not be reliable.
Dependency Management: Real-time environments need to handle dependencies between different parts of the codebase. A change in one area might break the compilation of another, even if both changes are individually valid.on.
Proposed Solutions
Here's a breakdown of potential solutions:
Real-time Code Understanding: Leverage Abstract Syntax Trees (ASTs) for efficient code analysis and manipulation, enabling near real-time understanding of changes.
Code Regions and Dependency Graphs: Utilize Language Server Protocol (LSP) or similar techniques to define code regions based on dependencies. This allows developers to work on isolated sections without interference.
Transparent Locking Mechanism: Implement a transparent locking system that notifies developers when a code region is being edited.
Shadow Trees for Concurrent Editing: Create shadow trees for concurrent editing within locked regions. This enables independent work while ensuring individual compilation success.
Checkpointing and Collaboration: Introduce mechanisms for near real-time checkpoints or commits, facilitating collaboration and iterative development.
Conflict Resolution with CRDTs: Leverage CRDTs for automatic conflict resolution, maintaining codebase consistency without manual intervention.
Building on Existing Work
Several existing projects offer valuable insights:
Otte by Martin Kleppmann: Explores CRDTs for real-time collaboration (https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydra.html).
Yjs: A JavaScript library for real-time collaborative editing applications, potentially serving as a foundation for a real-time VCS (https://github.com/yjs/yjs).
Automerge by Martin Kleppmann: Delves deeper into combining CRDTs with version control, exploring trade-offs between real-time collaboration and traditional VCS features (https://martin.kleppmann.com/2022/03/28/rainbowfs-workshop.html).
Looking Ahead: A Long Road to Production
It's important to remember that Google Wave's initial announcement in 2009 predates the real-time features introduced in Google Docs by a decade. Taking a promising technology from concept to production-ready solution can be a lengthy process. While challenges remain, CRDTs hold immense potential for transforming version control into a seamless, real-time collaborative experience for developers.
Further Reading
Existing code editing tools like Visual Studio Live Share, Google Docs, and CodeSandbox offer real-time collaboration features, but lack the ability to guarantee compilation. CRDTs have the potential to bridge this gap here.

