{"id":13672019,"url":"https://github.com/shosti/wraft","last_synced_at":"2025-04-13T05:22:26.258Z","repository":{"id":145918099,"uuid":"428779648","full_name":"shosti/wraft","owner":"shosti","description":"Raft distributed consensus for WebAssembly in Rust","archived":false,"fork":false,"pushed_at":"2021-11-30T21:35:07.000Z","size":568,"stargazers_count":68,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T22:11:06.328Z","etag":null,"topics":["raft","rust","wasm","webrtc"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shosti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-16T18:59:22.000Z","updated_at":"2025-01-30T18:48:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0b62906-6004-45bb-ab79-7c1047572c1f","html_url":"https://github.com/shosti/wraft","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shosti%2Fwraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shosti%2Fwraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shosti%2Fwraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shosti%2Fwraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shosti","download_url":"https://codeload.github.com/shosti/wraft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248666922,"owners_count":21142344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raft","rust","wasm","webrtc"],"created_at":"2024-08-02T09:01:24.369Z","updated_at":"2025-04-13T05:22:26.232Z","avatar_url":"https://github.com/shosti.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# WRaft: Raft in WebAssembly\n\n## What is this?\n\nA toy implementation of the [Raft Consensus Algorithm](https://raft.github.io/)\nfor [WebAssembly](https://webassembly.org/), written in Rust. Basically, it\nsynchronizes state across three browser windows in a peer-to-peer fashion.\n\n## Why is this?\n\nBecause I was curious to see if I could get it to work 😄. I can't think of any\nreal-world use-cases off the top of my head, but if you can, please open an\nissue and let me know!\n\n## How does it work?\n\nWRaft uses [WebRTC data\nchannels](https://webrtc.org/getting-started/data-channels) to set up\ncommunication between the browser windows. Sadly [WebRTC isn't purely\npeer-to-peer](https://www.youtube.com/watch?v=Y1mx7cx6ckI), so there's a\nseparate WebSocket-based service (`webrtc-introducer`) that \"introduces\" the\nbrowser windows to each other before the cluster can start. The browser windows\ncan be on the same computer or different machines on a LAN (or different\nnetworks, theoretically, but I haven't tested that yet). Firefox and Chrome (or\nany combination of the two) seem to work; Safari seems to not work.\n\nOnce the browser windows have been introduced to each other, a Raft cluster is\nstarted and messages sent to one browser window are reliably replicated to all\nthree in a consistent order (as long as everything's working correctly 😉). The\nmessages are persisted to the browser's local storage so they'll survive browser\nrestarts. The cluster will continue functioning normally even if one window\nstops, and can recover if two windows stop.\n\nThe \"replicated messages\" could be any\n[serializable](https://docs.serde.rs/serde/trait.Serialize.html) Rust type.\nThere's a `raft::State` trait that allows the user to \"plug in\" any\nstate-machine-like-thing into the Raft server (using Rust generics). For the\nexample apps, I used [yew](https://yew.rs/) with the \"state machine\" more or\nless mapping to the application state. (You could also use a `HashMap` to get a\ndistributed key/value store à la etcd.)\n\nThere's currently no way to expand beyond three browser windows (or any notion\nof a \"client\" outside of the cluster servers). I have some ideas for how it\nmight work, though.\n\n## Can I try it?\n\nYes! There are two basic \"demo apps\" included in the library, publicly hosted at\nhttps://wraft0.eevans.co/. The apps are:\n\n- [Synchronized TodoMVC](https://wraft0.eevans.co/todo).\n- An extremely basic [benchmarking tool](https://wraft0.eevans.co/bench) to get\n  a sense of performance.\n\nTo use either app, you'll need to open the app in different browser windows with\ndifferent hosts (`wraft0.eevans.co`, `wraft1.eevans.co`, and `wraft2.eevans.co`)\n(they need to be different host names so they have independent Local\nStorage). The app should then start up and you can try it!\n\n## Is it fast?\n\nI don't have much to compare it to, but from some basic testing it seems pretty\nfast to me! In the best-case scenario (three Chromium browsers on the same\nmachine) I've seen ~2000 writes/second which should be enough for any use case I\ncan think of 😄. (The bigger issue is that you hit the local storage quota\npretty fast; log compaction would have to be implemented to work around that.)\nFirefox seems to top out at ~800 writes/second.\n\n## What parts of Raft are implemented?\n\nFor the Raft nerds out there, so far I've only implemented the \"basic algorithm\"\n(basically what's in the [TLA spec](https://github.com/ongardie/raft.tla)). To\nmake it more useful, you'd probably need:\n\n- Log compaction/snapshots (the API is designed to make this possible, but it's\n  completely unimplemented).\n\n- Cluster membership changes (I haven't really looked into this yet).\n\nNo promises that either of those will ever happen, but I might try implementing\nthem if I have time.\n\n## Should I use it in production?\n\n**No!** (At least not in its current state.) Documentation, error handling, and\ntesting are basically non-existent, and I haven't implemented some harder parts\nof Raft like log compaction and cluster membership changes. There are a few bugs\nI know about and almost certainly many more I don't!\n\nIf you have an actual use case for this, open an issue to let me know and I'll\nthink about turning it into a proper Crate and/or NPM package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshosti%2Fwraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshosti%2Fwraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshosti%2Fwraft/lists"}