Go-Load-Balancer is a lightweight load-balancer built in Golang. It includes implementations for round-robin static routing and least connection dynamic routing, offering a simple yet powerful solution for distributing network traffic efficiently.
Table of Contents
Go-Load-Balancer is a lightweight load-balancer built in Golang. It supports round-robin static routing and least connection dynamic routing, making it an ideal tool for evenly distributing traffic across multiple servers.
A load balancer is a network device or software that distributes incoming network traffic across multiple servers. This helps ensure that no single server becomes overwhelmed, improving reliability, availability, and scalability.
Static routing refers to a predetermined, fixed path that network traffic follows. It doesn't change unless manually adjusted, making it simple but inflexible.
Round Robin is a static routing method where requests are distributed in a cyclic manner. Each server in the pool receives an equal number of requests in turn, regardless of server load or capacity.
Go-Load-Balancer-Round-Robin-Demo.mp4
Dynamic routing adjusts the path of network traffic based on real-time conditions, such as server load or network congestion. This helps optimize performance and resource utilization.
The Least Connection method is a dynamic routing strategy that directs new requests to the server with the fewest active connections. This helps balance the load more evenly, especially in environments with varying server capacities or request processing times.
NOTE: Here, I have set up 3 demo servers where the sleep time simulates computation time, varying for each server based on its processing power and input data. As seen in the response, the 2nd server, with the shortest sleep time (representing faster computation), handles more requests due to its quicker processing.
Go-Load-Balancer-Least-Connection-Demo.mp4
- Golang - An open-source programming language.
To get started with go-load-balancer, follow these steps:
- Install Golang: Download and install Golang from the official website.
- Set Up Your Workspace: Create a new directory for your project and set your
GOPATH
environment variable to point to this directory. - Initialize Your Project: Inside your project directory, run:
go mod init github.com/your-username/go-load-balancer
- Run without Debugging:
go run main.go
- Clone the repo:
git clone https://github.com/Uttkarsh-raj/go-load-balancer
- Install the packages:
go mod tidy
- POST "/addServer"
- Request as:
- body
{ "address":"https://server_address.com" }
- body
- Response as:
- Success: Respective output.
{ "message": "Server added successfully", "success": true }
- Failure: "message" : Error.
{ "message": "error: Unable to add the server", "success": false }
- Success: Respective output.
- Request as:
- DELETE "/delete"
- Request as:
- body
{ "address":"https://server_address.com" }
- body
- Response as:
- Success: Respective output.
{ "message": "Server deleted successfully", "success": true }
- Failure: "message" : Error.
{ "message": "error: Server does not exists", "success": false }
- Success: Respective output.
- Request as:
- ANY "/path_for_the_servers"
- Request as:
- body as required by the servers being handled by the load-balancer
- Response as:
- Success: Respective output.
- Failure: "message" : Error.
- Request as:
The Go-Load-Balancer project offers a flexible solution for load balancing across multiple servers. It supports:
- Web Application Scaling: Distribute user requests across multiple web servers to handle increased traffic and ensure smooth performance.
- API Gateway: Balance incoming API requests among backend services, improving reliability and response time.
- Database Load Management: Distribute queries across multiple database instances to prevent any single instance from being overwhelmed.


Contributions make the open-source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
). - Commit your Changes (
git commit -m 'Add some AmazingFeature'
). - Push to the Branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
This project is licensed under the MIT License, a permissive open-source license that allows for the use, modification, and distribution of this software. It grants users the freedom to use the software for any purpose, including commercial purposes, as long as the original copyright and license notice is included. See the LICENSE file for more information. (back to top)
Uttkarsh Raj - GitHub
Project Link: https://github.com/Uttkarsh-raj/go-load-balancer