convergent
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.
Types
| 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 |
Usage
[]
= "0.1"
use ;
let mut node_a = new;
let mut node_b = new;
node_a.increment;
node_b.increment;
node_a.merge;
assert_eq!;
Design
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.
Related
hlc_id— Hybrid Logical Clock IDs (used byLWWRegister)- A comprehensive study of CRDTs — Shapiro et al., 2011
License
MIT