{"id":17382955,"url":"https://github.com/kei-k23/go-load-balancer","last_synced_at":"2026-03-08T07:32:31.765Z","repository":{"id":254596342,"uuid":"846998094","full_name":"Kei-K23/go-load-balancer","owner":"Kei-K23","description":"Creating a full-featured load balancer in Go that can distribute HTTP requests to multiple backend servers using weighted round-robin algorithm, Circuit Breaker and other.","archived":false,"fork":false,"pushed_at":"2024-08-25T14:42:43.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T07:06:45.371Z","etag":null,"topics":["go","golang","load-balancer","load-testing","shell-script","tool"],"latest_commit_sha":null,"homepage":"","language":"Go","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/Kei-K23.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":"2024-08-24T14:58:46.000Z","updated_at":"2024-09-18T01:06:25.000Z","dependencies_parsed_at":"2024-08-24T16:49:39.745Z","dependency_job_id":"4e55b1a0-99ff-438b-a3bb-018f404f4f71","html_url":"https://github.com/Kei-K23/go-load-balancer","commit_stats":null,"previous_names":["kei-k23/go-load-balancer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Kei-K23/go-load-balancer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2Fgo-load-balancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2Fgo-load-balancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2Fgo-load-balancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2Fgo-load-balancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kei-K23","download_url":"https://codeload.github.com/Kei-K23/go-load-balancer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kei-K23%2Fgo-load-balancer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268484052,"owners_count":24257634,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","load-balancer","load-testing","shell-script","tool"],"created_at":"2024-10-16T07:39:59.625Z","updated_at":"2025-12-07T07:02:27.487Z","avatar_url":"https://github.com/Kei-K23.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go load balancer\n\nCreating a full-featured load balancer in Go that can distribute HTTP requests to multiple backend servers using weighted round-robin algorithm, Circuit Breaker and other. This project uses only `Go standard library`.\n\n## Features\n\n- **Server Pool**: Maintains a list of backend servers.\n- **Weighted Round-Robin Algorithm**: Selects servers based on dynamically adjusted weights.\n- **Health Checks**: Periodically checks the health of each server and updates their status.\n- **Circuit Breaker**: Protects failing servers from being overloaded by temporarily removing them from the selection pool.\n- **Dynamic Weight Adjustment**: Adjusts server weights based on performance, including response time and failure count.\n\n## Project Structure\n\n- `main.go`: Entry point for the load balancer server.\n- `load-balancer/main.go`: Contains the core load balancer logic.\n- `logger/main.go`: Custom logger implementation for consistent logging throughout the application.\n- `server*/` : Backend servers\n\n## Getting Started\n\n### Prerequisites\n\n- Go 1.23.0 (1.20+)\n- A set of backend servers to balance. For this example, servers are expected to be running on `http://localhost:8081`, `http://localhost:8082`, and `http://localhost:8083` (You can add more servers depending on what your need).\n\n### Installation\n\n1. **Clone the repository:**\n\n```sh\ngit clone https://github.com/Kei-K23/go-load-balancer\ncd go-load-balancer\n```\n\n2. **Run the Load Balancer:**\n\n```sh\ngo run main.go\n```\n\n3. **Run backend servers**\n\n```sh\n# navigate to the server folder\ncd server1\n# run Go file\ngo run main.go\n# You can run backend servers as you need\n```\n\n4. **Stop the Load Balancer:**\n\nPress `Ctrl+C` in the terminal or send a termination signal to gracefully shut down the load balancer.\n\n### Adding Backend servers\n\nI write ready to use shell script to generate `Go backend servers` in the project root path. All you need to do is adding the backend server address to main entry point for load balancer.\n\n1. **Run add server shell script in the root terminal to create new server**\n\n```sh\n# Make sure server name should be in the format of name+number e.g(server5, server6 up to server9)\n./add_server.sh server4\n```\n\n2. **Add newly added server address to load balancer**\n\n```go\n// /main.go\n\n// This is predefine backend servers\nserverPool.AddServer(loadbalancer.NewServer(\"http://localhost:8081\"))\nserverPool.AddServer(loadbalancer.NewServer(\"http://localhost:8082\"))\nserverPool.AddServer(loadbalancer.NewServer(\"http://localhost:8083\"))\n// e.g. serverPool.AddServer(loadbalancer.NewServer(\"http://localhost:8084\"))\n// add more backend servers here\n```\n\n### Testing the load balancer and backend servers\n\nTo perform load-testing, you can use any load-testing tool that you want. In my case, I use `JMeter` and prepare the test plan.\n\n```sh\n# Run this command in the root terminal\njmeter -n -t /Your-Path/go-load-balancer/load-testing.jmx -l /Your-Path/go-load-balancer/results.jtl -Jproperty_name=value\n\n# e.g for my case jmeter -n -t /Users/user/Desktop/projects/go-projects/go-load-balancer/load-testing.jmx -l /Users/user/Desktop/projects/go-projects/go-load-balancer/results.jtl -Jproperty_name=value\n```\n\n## Todo\n\n- [ ] Publish load-balancer as `Go package`. (I will publish as package only when the code meet the requirement as actual real-world load balancer)\n- [ ] Add request filtering and banning (To be as like API Gateway but API Gateway and Load balancer are different topic)\n- [ ] Add failure recovery\n- [ ] Add testing\n- [ ] Add more features, improve performance\n\n## Contributing\n\nContributions are welcome! Please fork the repository and open a pull request with your changes.\n\n## License\n\nThis project is licensed under the [Apache-2.0 License](/LICENSE). See the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkei-k23%2Fgo-load-balancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkei-k23%2Fgo-load-balancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkei-k23%2Fgo-load-balancer/lists"}