{"id":19632636,"url":"https://github.com/jacky-xbb/raf","last_synced_at":"2025-04-28T06:33:48.267Z","repository":{"id":43485881,"uuid":"267196458","full_name":"jacky-xbb/Raf","owner":"jacky-xbb","description":"An Elixir library which implements the Raft consensus protocol","archived":false,"fork":false,"pushed_at":"2023-10-16T06:45:13.000Z","size":46,"stargazers_count":32,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T07:23:32.603Z","etag":null,"topics":["distributed-systems","raft-consensus-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacky-xbb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-27T02:00:16.000Z","updated_at":"2024-03-11T04:33:47.000Z","dependencies_parsed_at":"2022-09-10T20:31:45.302Z","dependency_job_id":null,"html_url":"https://github.com/jacky-xbb/Raf","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/jacky-xbb%2FRaf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacky-xbb%2FRaf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacky-xbb%2FRaf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacky-xbb%2FRaf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacky-xbb","download_url":"https://codeload.github.com/jacky-xbb/Raf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251266348,"owners_count":21561815,"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":["distributed-systems","raft-consensus-algorithm"],"created_at":"2024-11-11T12:14:48.736Z","updated_at":"2025-04-28T06:33:45.281Z","avatar_url":"https://github.com/jacky-xbb.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raf\n\n## Overview\nRaf is an Elixir implementation of the Raft distributed consensus protocol. It provides users with an api for building consistent (2F+1 CP), distributed state machines. Raft protocol is described in the [original\npaper](https://raft.github.io/raft.pdf).\n\n\n## Features\n- Leader election\n- Log replication\n- Configuration changes\n\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `raf` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:raf, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Example\n\n### Launch 3 nodes\n\n```elixir\n$ iex --sname peer1@localhost -S mix\niex(peer1@localhost)1\u003e Raf.start_test_node(:peer1)\n\n$ iex --sname peer2@localhost -S mix\niex(peer2@localhost)1\u003e Raf.start_test_node(:peer2)\n\n$ iex --sname peer3@localhost -S mix\niex(peer3@localhost)1\u003e Raf.start_test_node(:peer3)\n```\n\nwhen peers have been running. You can check peers' status:\n\n```elixir\n:sys.get_status(:peer1)\nor\n:sys.get_state(:peer1)\n```\n\n### Config cluster\n\nAt this point all the peers are in the `follow` state. In order to get them to communicate we need to define\na cluster configuration. In our case, we'll run on node `peer1`:\n\n```elixir\npeers = [{:peer1, :peer1@localhost},\n        {:peer2, :peer2@localhost},\n        {:peer3, :peer3@localhost}]\nRaf.set_config(:peer1, peers)\n```\n\nOnce election is done. You can see who is the current leader:\n\n```elixir\niex(peer2@localhost)3\u003e Raf.get_leader(:peer2)\n{:peer1, :peer1@localhost}\n```\n\n### Write Operations\n\n```elixir\n# Create a new ets table\nRaf.write(:peer1, {:new, :sometable})\n\n# Store an erlang term in that table\nRaf.write(:peer1, {:put, :sometable, :somekey, :someval})\n\n# Delete a term from the table\nRaf.write(:peer1, {:delete, :sometable, :somekey})\n\n# Delete a table\nRaf.write(:peer1, {:delete, :sometable})\n```\n\n### Read Operations\n\n```elixir\n# Read an erlang term\nRaf.read(:peer1, {:get, :sometable, :somekey})\n\n# list tables\nRaf.read(:peer1, :list_tables)\n\n# list keys\nRaf.read(:peer1, {:list_keys, :somekey})\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacky-xbb%2Fraf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacky-xbb%2Fraf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacky-xbb%2Fraf/lists"}