https://github.com/nomasystems/nbully
An OTP application for leader election.
https://github.com/nomasystems/nbully
bully-algorithm erlang-library
Last synced: 3 months ago
JSON representation
An OTP application for leader election.
- Host: GitHub
- URL: https://github.com/nomasystems/nbully
- Owner: nomasystems
- License: apache-2.0
- Created: 2022-04-29T11:33:06.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-08-25T09:34:34.000Z (9 months ago)
- Last Synced: 2025-08-25T11:02:02.730Z (9 months ago)
- Topics: bully-algorithm, erlang-library
- Language: Erlang
- Homepage:
- Size: 43 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# nbully
An OTP application for leader election.
The nbully application starts a supervisor that supervises a worker process. This process runs in every node and consensuates node leadership with its homologues in other nodes.
## Status
[](https://github.com/nomasystems/nbully/actions/workflows/ci.yml)
## Prerequisites



## Usage
In your `rebar.config` file, add the dependency:
```erl
{deps, [
{nbully, {git, "git@github.com:nomasystems/nbully.git", {branch, "main"}}}
]}.
```
Then, once the application is started, you can consult `nbully:leader/0` to know which node is the current leader. This value is the same for all nodes connected through `net_kernel` and might only change when nodes go up or down.
You can also use `nbully:subscribe/0` to receive live updates when the leader changes in the form of a message `{nbully_leader_update, Node}`. For example:
```erl
ok = nbully:subscribe(),
InitialLeader = nbully:leader(),
% [...]
NewLeader =
receive
{nbully_leader_update, Node} -> Node
after 1000 -> InitialLeader
end,
LeaderIsMe = node() =:= NewLeader,
% [...]
ok = nbully:unsubscribe().
```
## Support
Any doubt or suggestion? Please, check out [our issue tracker](https://github.com/nomasystems/nbully/issues).
## Contributing
Pull requests are welcome. Please read the [contributing guidelines](CONTRIBUTING.md) to know more about contribution.