{"id":42382057,"url":"https://github.com/rhodey/tinyraftplus","last_synced_at":"2026-01-27T22:01:11.935Z","repository":{"id":318727256,"uuid":"922301042","full_name":"rhodey/tinyraftplus","owner":"rhodey","description":"TinyRaft with extras","archived":false,"fork":false,"pushed_at":"2025-10-25T21:46:15.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-25T23:25:22.551Z","etag":null,"topics":["consensus","raft"],"latest_commit_sha":null,"homepage":"https://lock.host","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhodey.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-25T20:51:50.000Z","updated_at":"2025-10-25T21:41:40.000Z","dependencies_parsed_at":"2025-10-13T04:03:26.725Z","dependency_job_id":"7a2e19ca-7aec-474f-898d-01fdede0dc83","html_url":"https://github.com/rhodey/tinyraftplus","commit_stats":null,"previous_names":["rhodey/tinyraftplus"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/rhodey/tinyraftplus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhodey%2Ftinyraftplus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhodey%2Ftinyraftplus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhodey%2Ftinyraftplus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhodey%2Ftinyraftplus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhodey","download_url":"https://codeload.github.com/rhodey/tinyraftplus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhodey%2Ftinyraftplus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28823915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T18:44:20.126Z","status":"ssl_error","status_checked_at":"2026-01-27T18:44:09.161Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["consensus","raft"],"created_at":"2026-01-27T22:01:10.075Z","updated_at":"2026-01-27T22:01:11.930Z","avatar_url":"https://github.com/rhodey.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyRaftPlus\nThis is the [TinyRaft](https://www.npmjs.com/package/tinyraft) API with extras. As with all Raft implementations a leader is elected and the network can survive if any majority of nodes are alive, what has been added to tinyraft is...\n\n### Log replication\nA log with append(), appendBatch(), txn(), commit(), abort(), trim(), iter()\n\n### Replication groups\nNodes may be assigned groups to support for example majority replication in both CloudA, CloudB\n\n### BigInt sequence numbers\nUses JS native BigInt for sequence numbers so you can grow to infinity\n\n## Usage\n```js\nconst { RaftNode, FsLog } = require('tinyraftplus')\n\nconst toBuf = (obj) =\u003e Buffer.from(JSON.stringify(obj), 'utf8')\nconst toObj = (buf) =\u003e JSON.parse(buf.toString('utf8'))\n\nconst ids = new Array(3).fill(0).map((z, idx) =\u003e ++idx)\nconst nodes = ids.map((id) =\u003e node(id, ids))\n\nfunction node(id, ids) {\n  const send = (to, msg) =\u003e {\n    const node = nodes.find((node) =\u003e node.id === to)\n    node.onReceive(id, msg) // from, msg\n  }\n  const log = new FsLog('/tmp/', 'node'+id)\n  const opts = { quorum: 3 } // full repl for demo\n  return new RaftNode(id, ids, send, log, opts)\n}\n\nasync function main() {\n  await Promise.all(nodes.map((node) =\u003e node.open()))\n  console.log('open')\n  await Promise.all(nodes.map((node) =\u003e node.awaitLeader()))\n  console.log('have leader')\n\n  // append to any node = fwd to leader\n  let seq = await nodes[0].append(toBuf({ a: 1 }))\n  console.log('seq =', seq)\n  seq = await nodes[1].append(toBuf({ b: 2 }))\n  console.log('seq =', seq)\n  seq = await nodes[2].append(toBuf({ c: 3 }))\n  console.log('seq =', seq)\n\n  console.log('head', toObj(nodes[0].head))\n  console.log('head', toObj(nodes[1].head))\n  console.log('head', toObj(nodes[2].head))\n\n  await Promise.all(nodes.map((node) =\u003e node.close()))\n}\n\nmain().catch(console.log)\n```\n```\nopen\nhave leader\nseq = 1n\nseq = 2n\nseq = 3n\nhead { c: 3 }\nhead { c: 3 }\nhead { c: 3 }\n```\n\n## State Machine (optional)\n```js\nconst { RaftNode, FsLog } = require('tinyraftplus')\n\nconst toBuf = (obj) =\u003e Buffer.from(JSON.stringify(obj), 'utf8')\nconst toObj = (buf) =\u003e JSON.parse(buf.toString('utf8'))\n\nconst ids = new Array(3).fill(0).map((z, idx) =\u003e ++idx)\nconst nodes = ids.map((id) =\u003e node(id, ids))\n\nfunction node(id, ids) {\n  // opts may be fn\n  const opts = () =\u003e {\n    let myCount = 0n\n    const apply = (bufs) =\u003e {\n      const results = []\n      bufs.forEach((buf) =\u003e results.push(buf ? ++myCount : null))\n      return results\n    }\n    const read = (cmd) =\u003e myCount\n    return { apply, read }\n  }\n  const send = (to, msg) =\u003e {\n    const node = nodes.find((node) =\u003e node.id === to)\n    node.onReceive(id, msg) // from, msg\n  }\n  const log = new FsLog('/tmp/', 'node'+id)\n  return new RaftNode(id, ids, send, log, opts)\n}\n\nasync function main() {\n  await Promise.all(nodes.map((node) =\u003e node.open()))\n  await Promise.all(nodes.map((node) =\u003e node.awaitLeader()))\n\n  // return type has changed\n  let ok = await nodes[0].append(toBuf({ a: 1 }))\n  let [seq, result] = ok\n  console.log('state', seq, result)\n\n  ok = await nodes[1].append(toBuf({ b: 2 }))\n  seq = ok[0]; result = ok[1]\n  console.log('state', seq, result)\n\n  ok = await nodes[2].append(toBuf({ c: 3 }))\n  seq = ok[0]; result = ok[1]\n  console.log('state', seq, result)\n\n  // read from any node = fwd to leader\n  const cmd = { any: 'type' }\n  ok = await nodes[0].read(cmd)\n  seq = ok[0]; result = ok[1]\n\n  console.log('read ', seq, result)\n\n  await Promise.all(nodes.map((node) =\u003e node.close()))\n}\n\nmain().catch(console.log)\n```\n```\nstate 1n 1n\nstate 2n 2n\nstate 3n 3n\nread  3n 3n\n```\n\n## You should know\nThe [Raft paper](https://raft.github.io/raft.pdf) explains that leaders must begin their term by appending a null buffer\n\nWith TinyRaftPlus seq begins with 0 but you see 1 in examples because of the null buffer\n\nYour state machine apply function will encounter nulls and should return null for null so be aware\n\n## RaftNode events\nRaftNode emits change, commit, apply, warn, and error\n\nChange is the same as [TinyRaft](https://www.npmjs.com/package/tinyraft), and commit and apply both emit a seq number\n\nWarn (warn) emits an instance of Error and these errors are errors that replication avoids / recovers from\n\n## Error events\nError (error) emits an instance of Error and these come only from operations with the log\n\nIf you get two error events in \u003c= 60 seconds you should restart the host\n\nIf node.open fails on restart the host filesystem is bad\n\nIf your filesystem is suspect use [XxHashEncoder](https://github.com/rhodey/tinyraftplus/blob/master/src/encoder.js#L63) from the start\n\n## Configuration\n+ [FsLog](https://github.com/rhodey/tinyraftplus/blob/master/src/fslog.js#L20)\n+ [MultiFsLog](https://github.com/rhodey/tinyraftplus/blob/master/src/multi.js#L35)\n+ [TimeoutLog](https://github.com/rhodey/tinyraftplus/blob/master/src/timeout.js#L19)\n+ [XxHashEncoder](https://github.com/rhodey/tinyraftplus/blob/master/src/encoder.js#L63)\n+ [EncryptingEncoder](https://github.com/rhodey/tinyraftplus/blob/master/src/encoder.js#L135)\n+ [RaftNode](https://github.com/rhodey/tinyraftplus/blob/master/src/node.js#L68)\n\n## Performance\nNode v20.11.0 (LTS) is best\n+ FsLog append = 650 bufs/sec\n+ FsLog append + txn = 50,000 bufs/sec\n+ FsLog appendBatch = 100,000 bufs/sec\n+ RaftNode append = 275 bufs/sec\n+ RaftNode appendBatch = 100,000 bufs/sec\n\n## Test\nThe [tests](https://github.com/rhodey/tinyraftplus/tree/master/test) include 3744 assertions\n\nThe API is stable to dev against but I intend to add approx 20% more tests\n```\nnpm run test\n```\n\n## Tcp\nSee [example3.js](https://github.com/rhodey/tinyraftplus/blob/master/example3.js) which shows use TCP and advanced options\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhodey%2Ftinyraftplus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhodey%2Ftinyraftplus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhodey%2Ftinyraftplus/lists"}