A Practical Guide to Building Distributed Collaborative Systems
Introduction
- What This Book Is About
- Who This Book Is For
- How This Book Is Organized
- The Codebase
- What You Will Be Able To Do
Chapter 1: The Collaboration Problem
- The Broken Promise of Centralized Collaboration
- Real-World Failure Scenarios
- Why Locking Fails at Scale
- The Offline-First Imperative
- A Preview of What Is Possible
Chapter 2: Foundations of Distributed Replication
- Single Source of Truth and Its Limits
- Replication Architectures
- Consistency Models From Strong to Eventual
- The CAP Theorem and Its Implications
- Linearizability Versus Sequential Consistency
- Partition Tolerance in Real Networks
- The Trade-Off Spectrum
Chapter 3: Causality and Logical Time
- The Nature of Causality in Distributed Systems
- Happens-Before and Partial Ordering
- Lamport Timestamps
- Vector Clocks
- Dot Clocks and Dot Updates
- Detecting Causality Violations
Chapter 4: Eventual Consistency and Convergence
- What Eventual Consistency Actually Means
- Convergence Conditions
- Monotonicity and the Path to Agreement
- When Eventual Consistency Is Not Enough
- Measuring and Testing Convergence
- The Split-Brain Problem
- Causal Delivery and Reliable Broadcast
- Summary of Convergence
Chapter 5: Introducing CRDTs
- The CRDT Promise
- Formal Definition and Required Properties
- Join Semilattices and Monotonicity
- Why CRDTs Always Converge
- Strong Eventual Consistency
- The Trade-Offs of Unconditional Convergence
- CRDTs and the CAP Theorem
- Summary
Chapter 6: Building Your CRDT Toolkit
- Project Setup and Dependencies
- Core Types and Interfaces
- Replica Identity
- Dot Clocks
- Serialization and Canonical Encoding
- The Replica Model
- A Minimal Test Harness
Chapter 7: Registers and Flags
- The Write-Wins Register
- The Last-Writer-Wins Register
- The Write-Wins Register with Timestamps
- Multi-Value Registers
- Dot Clocks for Register Synchronization
- Flags and Presence Bits
- Complete Example: Running Multiple Replicas
- Summary
Chapter 8: Counters and Numeric CRDTs
- The Grow-Only Counter
- Positive-Negative Counters
- The Replica-Numbered Counter
- Bounded and Rolling Counters
- Floating-Point and Monetary Counters
- Complete Example
- Summary
Chapter 9: Sets
- The Concurrency Problem for Sets
- The Grow-Only Set
- The Two-Phase Set
- Observed-Remove Sets
- Last-Writer-Wins Sets
- Union-Only and Intersection-Only Sets
- Implementation and Replication
- Summary
Chapter 10: Maps and Nested Structures
- Map-Specific Concurrency Issues
- The LWW-Register Map
- The MMRG Map CRDT
- Nesting CRDTs Within Maps
- Deep Convergence Guarantees
- Memory and Tombstone Growth in Maps
- Summary
Chapter 11: The Synchronization Protocol
- Synchronization Requirements
- Full State Transfer
- Delta-State Replication
- Delta Sync with Dot Clocks
- Causal Delivery and Message Ordering
- Anti-Entropy and Peer Discovery
- Implementation of the Sync Protocol
- Summary
Chapter 12: Sequences and Ordered Collections
- Why Sequences Are Hard
- Positioning in Concurrent Documents
- RGA Sequences
- Logoot Sequences
- Positioning Without Gaps
- Implementation and Replication
- Summary
Chapter 13: Text Editing CRDTs
- The Collaborative Editing Problem
- Document State Representation
- Concurrent Insertion Resolution
- Concurrent Deletion Resolution
- Cursor Positions and Selection
- Real-Time and Offline Editing
- Summary
Chapter 14: Building a Distributed Key-Value Store
- Architecture and Design
- The Replica Process
- Persistence and Recovery
- Peer Communication
- Testing with Multiple Replicas
- Running the System
- Summary
Chapter 15: Building a Collaborative Text Editor
- Editor Architecture
- Client-Side CRDT Integration
- WebSocket Synchronization
- Offline Editing and Replay
- Concurrent Editing Tests
- Complete Working Example
- Summary
Chapter 16: Metadata Growth, Tombstones, and Garbage Collection
- The Tombstone Problem
- Why CRDTs Leak Memory
- Garbage Collection in CRDTs
- Compaction Strategies
- Bounded Metadata Designs
- Summary
Chapter 17: Production Concerns
- Security and Authorization
- Malicious and Invalid Operations
- Performance Optimization
- Observability and Debugging
- Schema Evolution and Versioning
- Scaling to Many Replicas
- Summary
Chapter 18: CRDTs Versus Alternatives
- Operational Transformation
- Centralized Synchronization
- Distributed Locking
- Consensus Protocols
- Event Sourcing and CQRS
- Database Replication Strategies
- Decision Framework
- Summary
Chapter 19: Real-World CRDT Systems
- Riak Distributed Database
- Yjs Collaborative Framework
- Automerge Offline-First Library
- Figma and Real-Time Design Tools
- Emerging CRDT Databases
- Lessons from Production
- Summary
Chapter 20: Conclusion and Where to Go
- The CRDT Design Philosophy
- Where CRDTs Are Going
- Open Problems and Research Frontiers
- A Final Architecture Checklist
- Final Thoughts
- Bibliography and Further Reading