Lightweight, composable CRDTs (Conflict-Free Replicated Data Types) for decentralized systems.
CRDTs are data structures that can be replicated across nodes, modified independently, and merged with a mathematically guaranteed consistent result — no central coordination required.
| Type | Description | Use case |
|---|---|---|
GCounter |
Grow-only counter | View counts, event tracking |
PNCounter |
Positive-Negative counter | Likes/dislikes, stock levels |
LWWRegister |
Last-Writer-Wins register | User profile fields, settings |
ORSet |
Observed-Remove set | Shopping carts, tag lists |
[dependencies]
convergent = "0.1"use convergent::{GCounter, Merge};
let mut node_a = GCounter::new("a");
let mut node_b = GCounter::new("b");
node_a.increment(3);
node_b.increment(5);
node_a.merge(&node_b);
assert_eq!(node_a.value(), 8);Every type implements the Merge trait, which guarantees:
- Commutative —
a.merge(b) == b.merge(a) - Associative —
a.merge(b).merge(c) == a.merge(b.merge(c)) - Idempotent —
a.merge(a) == a
The LWWRegister uses hlc_id for causally-ordered timestamps, connecting this crate to the broader problem of time in distributed systems.
hlc_id— Hybrid Logical Clock IDs (used byLWWRegister)- A comprehensive study of CRDTs — Shapiro et al., 2011
MIT