Version Vector
Version Vectors are a fundamental concept in distributed systems that track the complete state of all peers by recording how many operations each peer has contributed.
What is a Version Vector?
A Version Vector is a map from peer IDs to operation counters, explicitly listing every peer and their operation count. It provides a complete picture of which operations are included in a version.
Example: { "peer-A": 5, "peer-B": 3 }
means this version includes operations 0-4 from peer A and operations 0-2 from peer B.
Key Characteristics
- Complete information: Explicitly lists all peers and their operation counts
- Grows with peer count: Size increases as more peers join
- No dependency on history: Can determine included operations without accessing the operation log
- Enables version comparison: Can easily check if one version includes another
Basic Usage
import { } from "loro-crdt";
const = new ();
.("1");
const = .("content");
.(0, "Hello");
// Get version vector
const = .();
.(.()); // Map { "1" => 1 }
When to Use Version Vectors
Version Vectors are ideal for:
- Synchronization protocols - Determine what updates to send between peers
- Network communication - Self-contained version information
- Distributed systems - Track state across multiple nodes
Comparison with Frontiers
Aspect | Version Vectors | Frontiers |
---|---|---|
Size | O(number of peers) | O(1-2) typically |
Information | Complete peer states | Boundary operations only |
Use Case | Synchronization | Checkpoints |
History Required | No | Yes, for full information |
Conversion with Frontiers
import { } from "loro-crdt";
const = new ();
const = .();
const = .(); // Convert to Frontiers
const = .(); // Convert back
Related Documentation
- Frontiers - Compact version representation
- Version Tutorial - Working with versions
- Version Deep Dive - Technical details