{"id":37194862,"url":"https://github.com/stefan-ctrl/bully","last_synced_at":"2026-01-14T22:39:22.747Z","repository":{"id":57651456,"uuid":"449359051","full_name":"stefan-ctrl/bully","owner":"stefan-ctrl","description":"A leader election program written in Go using Bully algorithm.","archived":false,"fork":true,"pushed_at":"2022-01-18T19:35:37.000Z","size":1427,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-06-20T01:59:54.010Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"monnand/bully","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefan-ctrl.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}},"created_at":"2022-01-18T16:20:38.000Z","updated_at":"2022-01-18T17:00:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/stefan-ctrl/bully","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/stefan-ctrl/bully","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-ctrl%2Fbully","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-ctrl%2Fbully/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-ctrl%2Fbully/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-ctrl%2Fbully/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefan-ctrl","download_url":"https://codeload.github.com/stefan-ctrl/bully/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefan-ctrl%2Fbully/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: 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":[],"created_at":"2026-01-14T22:39:22.120Z","updated_at":"2026-01-14T22:39:22.733Z","avatar_url":"https://github.com/stefan-ctrl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"bully\n=====\n\n[![Build Status](https://travis-ci.org/monnand/bully.png?branch=master)](https://travis-ci.org/monnand/bully)\n\nA leader election program written in [Go](http://golang.org)(golang) using\n[Bully leader election\nalgorithm](http://en.wikipedia.org/wiki/Bully_algorithm).\n\n**NOTE:** This program is indented to be used within LAN among small number of\nnodes. It is vulnerable to attack if it is exposed to outside network and it\nmay consume a lot of bandwith on a large cluster.\n\n## Quick start\n\n- Download and install:\n\n        go get github.com/monnand/bully\n\n- Suppose we want to run the program on two machines whose IPs are 192.168.1.67\n  and 192.168.1.68, respectively.\n- Run the following command on both machines:\n\n        bully -port=8117 -nodes=\"192.168.1.67:8117,192.168.1.68:8117\" -http=0.0.0.0:8080\n\n- To know who is the leader, use HTTP to connect one of the machines with path */leader*:\n\n        curl http://192.168.1.67:8080/leader\n\n## A real example\n\n### Starting from a single node\n\nLet's start with a real example. Again, we have two nodes at first, 192.168.1.67 and 192.168.1.68\n\nOn 192.168.1.67, I first execute the following command:\n\n        bully -port=8117 -nodes=\"192.168.1.67:8117,192.168.1.68:8117\" -http=0.0.0.0:8080\n\nThis command contains three arguments, *port*, *nodes* and *http*.\n- *port*: tells *bully* to listen on port 8117 waiting for other candidates'\n  connection.\n- *http*: tells *bully* to set up a web service on port 8080 accepting\n  connections from any client. The client will ask who is the leader using\n  HTTP.\n- *nodes*: tells *bully* the address (IP and port) of the initial set of candidates.\n\nNote that by executing the command above, *bully* will complain by printing the\nfollowing message at begining: \n\n        192.168.1.68:8117 cannot be added: dial tcp 192.168.1.68:8117: connection refused\n\nThis message says that it cannot connect to 192.168.1.68, which is correct\nbecause we haven't started it yet.\n\nNow, let's ask it who is the leader:\n\n        $ curl http://192.168.1.67:8080/leader\n        192.168.1.67\n\nThe returned value contains the IP address of the elected leader. In this case,\nthere is only one candidate, and apparently, it is the leader.\n\n### Adding one more node\n\nNow let's move on to 192.168.1.68 and start another *bully* instance with same command:\n\n        bully -port=8117 -nodes=\"192.168.1.67:8117,192.168.1.68:8117\" -http=0.0.0.0:8080\n\nSince both candidates specified in *nodes* argument are on-line, there is no more complain.\n\nThen we can ask both 192.168.1.67 and 192.168.1.68 who is the leader. And we\ncan always get the same answer:\n\n        $ curl http://192.168.1.67:8080/leader\n        192.168.1.68\n        $ curl http://192.168.1.68:8080/leader\n        192.168.1.68\n\nThe leader now is 192.168.1.68. In this case, they elected another node as the\nleader. But this is not always the case. Every time a new node join, there will\nbe a new election and the winner of the election may or may not be the\npreviours leader.\n\n### Playing with three nodes\n\nLet's say we want to add one more node into this cluster, whose IP is\n192.168.1.69. Only thing we need to do is to start a new instance of\n*bully* on 192.168.1.69 with almost the same command:\n\n        bully -port=8117 -nodes=\"192.168.1.67:8117,192.168.1.68:8117,192.168.1.69:8117\" -http=0.0.0.0:8080\n\nThe only changed part is the *nodes* parameter. Since we added one more node,\nthen we need to add it as an initial candidate. **The good part is that you don't\nneed to stop the other two instances running on 192.168.1.67 and 192.168.1.68.**\nThey will automatically update the candidate list and elect another leader.\n\nOnce the new instance started, we can query any of one of them about the leader\nusing HTTP:\n\n        $ curl http://192.168.1.67:8080/leader\n        192.168.1.68\n        $ curl http://192.168.1.68:8080/leader\n        192.168.1.68\n        $ curl http://192.168.1.69:8080/leader\n        192.168.1.68\n\nThis time, the leader is same as previours leader, which is 192.168.1.68.\n\n### Killing the leader\n\nWhat if the leader node crashed? The rest of the candidates will elect a new\nleader on the fly.\n\nSuppose we killed the leader in previours example and ask who is the leader to\nthe rest of the group:\n\n        $ curl http://192.168.1.67:8080/leader\n        192.168.1.67\n        $ curl http://192.168.1.69:8080/leader\n        192.168.1.67\n\nThey elected a new leader, which is 192.168.1.67.\n\nIf the old leader recovered, then it can join the group again by executing the\nfollowing command:\n\n        bully -port=8117 -nodes=\"192.168.1.67:8117,192.168.1.68:8117,192.168.1.69:8117\" -http=0.0.0.0:8080\n\n## Typical scenario\n\nThe good part of *bully* is that once we decided the set of candidates, we can\nuse exactly the same command with same parameters on any candidate node to\nstart *bully*. This is very nice because we can use the same virtual machine\nimage to start several VMs on the cloud.\n\nImaging we have a service needs a node to do some management work. Such work\nmay not be heavy but critical. So we need to have some backup servers in case\nof the manager down. Normally, 3 or 5 node will be enough. Since all nodes are\nsame, we need to select a leader node to do the job, let others keep running\nand wait the leader die. In this case, we can use *bully* to decide who is the\nleader, and elect another leader when the old one down or new one comes.\n\n## License\n\n[Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefan-ctrl%2Fbully","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefan-ctrl%2Fbully","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefan-ctrl%2Fbully/lists"}