This project implements a load balancer using the Go programming language and the Gin web framework. It forwards incoming requests to a set of backend servers using a round-robin strategy, with health checks to ensure only healthy servers receive traffic. This implementation also includes query parameter tracking for each forwarded request.
-
Proxies Setup:
- Backend servers are defined in a list (
targetServers). - Each server is wrapped in a
Proxyobject, which includes a reverse proxy and a health-checking mechanism.
- Backend servers are defined in a list (
-
Health Checks:
- The
HealthCheckerruns in a separate goroutine, periodically checking the/healthendpoint of each backend server.
- The
-
Request Handling:
- Incoming requests are routed to the next healthy backend server using a round-robin strategy.
- A query parameter (
reqCounter) is added to track requests.
-
Gin Web Framework:
- The application is built on the Gin framework, allowing for efficient request handling and routing.
- Go (>=1.16)
- Gin web framework (
go get -u github.com/gin-gonic/gin)
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory:
cd proxy-load-balancer - Run the application:
go run main.go
- Run the backend servers:
go run backend/main.go 8080 go run backend/main.go 8081 go run backend/main.go 8082 - Send curl command:
curl http://localhost/ping - Test using ab
ab -n 100000 -c 1 http://localhost/ping - Test using wrk
wrk -t1 -c5 -d60 http://localhost/ping
This project is licensed under the MIT License.
- Inspired the solution from Coding Challenges by John Crickett