DocsConceptsVersion Vector

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:

  1. Synchronization protocols - Determine what updates to send between peers
  2. Network communication - Self-contained version information
  3. Distributed systems - Track state across multiple nodes

Comparison with Frontiers

AspectVersion VectorsFrontiers
SizeO(number of peers)O(1-2) typically
InformationComplete peer statesBoundary operations only
Use CaseSynchronizationCheckpoints
History RequiredNoYes, for full information

Conversion with Frontiers

import {  } from "loro-crdt";
 
const  = new ();
const  = .();
const  = .();     // Convert to Frontiers
const  = .(); // Convert back