This project demonstrates the implementation of a simple load balancer in Go, capable of distributing HTTP requests across multiple backend servers using various algorithms such as round-robin, least-connections, and IP-hash.
- Go 1.18+ installed on your machine
- Git (for cloning the repository)
-
Clone the repository:
git clone https://github.com/nareshNishad/loadbalancer.git cd loadbalancer
-
Build and run the project::
go run main.go <algorithm>
Replace with one of the available algorithms: round-robin, least-connections, ip-hash.
-
Starting the Load Balancer The load balancer will start on http://localhost:8080 and will distribute incoming HTTP requests to the backend servers running on ports 8081, 8082, and 8083.
-
Sending Requests You can send requests to the load balancer using a web browser, curl, or Postman:
''' curl http://localhost:8080 ''' This request will be routed to one of the backend servers based on the chosen algorithm.
- Round-Robin Distributes requests evenly across all servers in a circular order.
- Least-Connections Directs requests to the server with the least number of active connections.
- IP-Hash Routes requests based on the client's IP address, ensuring that the same IP always hits the same backend server.