• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 2 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🏰 the first JSON-like Byzantine Fault Tolerant CRDT

Byzantine Fault Tolerant CRDTs

This work is mainly inspired by implementing Martin Kleppmann's 2022 paper on Making CRDTs Byzantine Fault Tolerant1 on top of a simplified Automerge implementation.

The goal is to show a working prototype that demonstrated in simple code the ideas behind

  1. An Automerge-like CRDT
  2. How a primitive list CRDT can be composed to create complex CRDTs like JSON
  3. How to add Byzantine Fault Tolerance to arbitrary CRDTs

Unlike most other CRDT implementations, I leave out many performance optimizations that would make the basic algorithm harder to understand.

Check out the accompanying blog post for this project!

Benchmarks

Altough this implementation does not optimize for performance, it still nonetheless performs quite well.

Benchmarking happened on a 2019 Macbook Pro with a 2.6GHz i7. Numbers are compared to Automerge which report their performance benchmarks here

# Ops Raw String (JS) Ours (basic) Ours (BFT) Automerge (JS) Automerge (Rust)
10k n/a 0.081s 1.793s 1.6s 0.047s
100k n/a 9.321s 38.842s 43.0s 0.597s
All (259k) 0.61s 88.610s 334.960s Out of Memory 1.780s
Memory 0.1MB 27.6MB 59.5MB 880MB 232.5MB

Flamegraph

To get some flamegraphs of the time graph on MacOS, run:

sudo cargo flamegraph --dev --root --bench speed

Further Work

This is mostly a learning/instructional project but there are a few places where performance improvements are obvious:

  1. This is backed by std::Vec which isn't great for random insert. Replace with a B-tree or something that provides better insert and find performance
    1. Diamond Types and Automerge (Rust) use a B-tree
    2. Yjs is backed by a doubly linked-list and caches last ~5-10 accessed locations (assumes that most edits happen sequentially; seeks are rare)
    3. (funnily enough, main peformance hit is dominated by find and not insert, see this flamegraph)
  2. Avoid calling find so many times. A few Automerge optimizations that were not implemented
    1. Use an index hint (especially for local inserts)
    2. Skipping the second find operation in integrate if sequence number is already larger
  3. Improve storage requirement. As of now, a single Op weighs in at over 168 bytes. This doesn't even fit in a single cache line!
  4. Implement 'transactions' for a group of changes that should be considered atomic.
    1. This would also speed up Ed25519 signature verification time by batching.
    2. For example, a peer might create an atomic 'transaction' that contains a bunch of changes.
  5. Currently, each character is a single op. Similar to Yjs, we can combine runs of characters into larger entities like what AndrΓ©, Luc, et al.2 suggest
  6. Implement proper persistence using SQLLite or something similar
  7. Compile the project to WASM and implement a transport layer so it can be used in browser. Something similar to Yjs' WebRTC Connector could work.

Acknowledgements

Thank you to Nalin Bhardwaj for helping me with my cryptography questions and Martin Kleppmann for his teaching materials and lectures which taught me a significant portion of what I've learned about distributed systems and CRDTs.

Footnotes

  1. Kleppmann, Martin. "Making CRDTs Byzantine Fault Tolerant." Proceedings of the 9th Workshop on Principles and Practice of Consistency for Distributed Data. 2022. ↩

  2. AndrΓ©, Luc, et al. "Supporting adaptable granularity of changes for massive-scale collaborative editing." 9th IEEE International Conference on Collaborative Computing: Networking, Applications and Worksharing. IEEE, 2013. ↩

More Repositories

1

quartz

🌱 a fast, batteries-included static-site generator that transforms Markdown content into fully functional websites
TypeScript
6,508
star
2

portal

πŸ”— zero-config peer-to-peer encrypted live folder syncing that respects your `.gitignore`
TypeScript
364
star
3

cursor-chat

πŸ’¬ cursor chat Γ  la Figma for digital co-existing + presence
TypeScript
219
star
4

hugo-obsidian

simple GitHub action to parse Markdown Links into a .json file for Hugo
Go
148
star
5

docker-explained

πŸ‹ wtf is docker and why is everyone talking about it
Dockerfile
121
star
6

ctrl-v

πŸ“‹ a modern, open-source pastebin with latex and markdown rendering support
JavaScript
117
star
7

tabspace

✍️ A scratchspace for your new Tab page
TypeScript
115
star
8

jackyzha0.github.io

✨ website v3
TypeScript
97
star
9

telescopic-text

πŸ”­ an open-source library to help with creating expandable text
TypeScript
88
star
10

nanoDB

πŸ’Ύ a simple, easy, and debuggable document database for prototyping and hackathons
Go
74
star
11

miniraft

πŸš£β€β™€οΈ <1kloc, well-documented Raft consensus algorithm implementation
Rust
46
star
12

DroneNet

Decentralized drone swarm communication for search and rescue missions
Python
35
star
13

min-react

Yet another minimal React template
JavaScript
17
star
14

paypaya

[πŸ† 5th place + Best Fintech at HackWestern] PayPaya -- SMS Money Transfer for Low Bandwidth Regions with Biometric Authentication
Python
15
star
15

rs-openai

A Rust crate for easy serving of OpenAI's API with rate limiting and token use tracking out of the box
Rust
12
star
16

discord-steward

🌿 A pace-layered approach to high-volume Discord Servers.
TypeScript
10
star
17

lite.css

a dead-simple just-add-water css library
HTML
10
star
18

template-react

For when create-react-app just doesn't give you what you want.
JavaScript
9
star
19

PacketBook

[πŸ† Top 30 at nwHacks 2018, SAP iXP Prize] PacketBook SMS financial inclusion platform powered by the Stellar Blockchain
JavaScript
7
star
20

play

artifact from interact circle on hackathon culture + play
JavaScript
7
star
21

NEAT-genetic-algo

BIOL111 Group Project
Python
6
star
22

treehacks2020-backend

[πŸ† Azure Prize at TreeHacks] readAR -- 🌲 TreeHacks 2020 Backend
Python
5
star
23

hruid

human-readable base16 IDs
JavaScript
5
star
24

hackTheNorth2018

πŸ“± Tapp.it! - Cryptopayments over NFC
Java
5
star
25

Speech2Braille

[πŸ† Silver Medal at CWSF] Tensorflow Implementation of TIMIT Deep BLSTM-CTC with Tensorboard Support
Python
5
star
26

go-auth-w-mongo

Simple session based authentication with Mux and MongoDB
Go
4
star
27

go-remote-debug

A quick tutorial on debugging containerized Go applications!
Go
3
star
28

htn22

HTN22 - Intro to Computer Networking and Peer-to-peer
HTML
3
star
29

front-proxy-PoC

Simple Envoy Service Mesh with External Authorization and Custom Header Injection.
Go
3
star
30

blog

some mildly coherent ramblings
CSS
3
star
31

jackyzha0

a cool readme
TypeScript
3
star
32

dotfiles

dotfiles n things
Lua
3
star
33

monGo-driver-wrapper

A small Go wrapper to reduce boilerplate of using the official Go Mongo Driver
Go
2
star
34

curius-viz

JavaScript
2
star
35

website-v2

✨ now with templating and other cool stuff ✨
CSS
2
star
36

riverbed

TypeScript
2
star
37

groupCalendar

A Group Web Calendar created with Meteor
JavaScript
1
star
38

python-spacegame

2D Top Down Space Shooter
Python
1
star
39

y-webrtc-signalling

a simple y-webrtc signalling server for use in serverless environments
JavaScript
1
star
40

apcs-spaceshooter

Short project for APCS A
Java
1
star
41

wholesome-bot

A fun little web scrapping project to bring some happiness to the world
HTML
1
star
42

dailycodingproblem

Python
1
star
43

gameoflife

Java Implementation of Conway's Game of Life
Java
1
star
44

playspace

playspace website
HTML
1
star