crdt-kit
Conflict-free Replicated Data Types for edge computing and local-first applications
Docs | Crate | Examples | Contributing
Why crdt-kit?
Problem: Existing CRDT libraries (Automerge, Yjs) are powerful but not optimized for resource-constrained environments like Raspberry Pi, mobile devices, or IoT.
Solution: crdt-kit provides battle-tested CRDT implementations designed for:
| Use Case | Description |
|---|---|
| Edge devices | Raspberry Pi, embedded systems, IoT sensors |
| Mobile apps | Offline-first with reliable sync |
| P2P networks | Bandwidth-efficient delta state |
| Low latency | Minimal overhead for real-time collaboration |
Quick Start
use *;
// Create a distributed counter
let mut counter = new;
counter.increment;
// On another device
let mut counter2 = new;
counter2.increment;
// Merge - they converge automatically
counter.merge;
assert_eq!;
Available CRDTs
Counters
| Type | Description | Use Case |
|---|---|---|
GCounter |
Grow-only counter | Page views, event counts |
PNCounter |
Increment & decrement | Inventory, likes/dislikes |
Registers
| Type | Description | Use Case |
|---|---|---|
LWWRegister |
Last-writer-wins | User profile fields |
MVRegister |
Multi-value (conflict-aware) | Collaborative editing |
Sets
| Type | Description | Use Case |
|---|---|---|
GSet |
Grow-only set | Tag collections, seen IDs |
TwoPSet |
Add & remove (permanent remove) | Blocklists |
ORSet |
Add & remove freely | Todo lists, shopping carts |
Installation
[]
= "0.1"
Examples
use *;
// OR-Set: collaborative todo list
let mut alice = new;
let mut bob = new;
alice.insert;
bob.insert;
// Sync - both items present
alice.merge;
assert!;
assert!;
// Remove and concurrent add - add wins!
alice.remove;
bob.insert;
alice.merge;
assert!; // concurrent add survives
use *;
// MV-Register: detect conflicts
let mut r1 = new;
let mut r2 = new;
r1.set;
r2.set;
r1.merge;
assert!; // both values preserved
// Application can show conflict to user for resolution
Run the included examples:
Benchmarks
Measured with cargo bench (Criterion, optimized build):
| Operation | Time |
|---|---|
| GCounter increment x1000 | 53 µs |
| GCounter merge 10 replicas | 1.1 µs |
| GCounter merge 100 replicas | 17.8 µs |
| PNCounter inc+dec x1000 | 60 µs |
| ORSet insert x1000 | 187 µs |
| ORSet merge 500+500 elements | 191 µs |
| GSet merge 1000+1000 elements | 102 µs |
| LWWRegister merge 100 replicas | 11.5 µs |
Run benchmarks yourself: cargo bench
Guarantees
All CRDTs in this library satisfy the Strong Eventual Consistency properties:
- Commutativity -
merge(a, b) == merge(b, a) - Associativity -
merge(a, merge(b, c)) == merge(merge(a, b), c) - Idempotency -
merge(a, a) == a
These properties are verified by 70 tests (52 unit + 9 integration + 9 doctests).
Roadmap
- G-Counter, PN-Counter
- LWW-Register, MV-Register
- G-Set, 2P-Set, OR-Set
- RGA List (ordered sequence)
- Text CRDT (collaborative text editing)
-
no_stdsupport (embedded systems) -
serdeserialization support - Delta-state optimization
- WASM bindings
Contributing
Contributions are welcome! Please read CONTRIBUTING.md before submitting a pull request.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.