This is a Layer 7 Application load balancer that handles HTTP requests. It implements a dynamic load balancing algorithm, and uses a threadpool to service incoming requests. The load balancer has health checks for connected servers, and is able to handle servers going down and coming back up by removing/adding them to the server pool. Additionally, the load balancer supports dynamic scaling by adjusting the thread pool size based on current load conditions.
First make sure Go is installed. This is the version I am using: go version go1.26.0 darwin/arm64
go version
Then run the main package to start the load balancer. In the root directory, run
go run .
Then start the backend servers in a different terminal. You can start up multiple server instances.
go run server/server.go <PORT NUMBER>
Then you can use curl commands to send requests to the load balancer.
curl -X POST http://localhost:<LOAD BALANCER PORT>/requests
curl -X POST http://localhost:<LOAD BALANCER PORT>/queue/status
or you can also use the go script to send multiple requests.
go run loadtest/main.go
The config file specifies the following configurations:
{
"load_balancer": {
"load_balancer_port": "8000"
},
"servers": {
"queue_capacity": 1000
},
"threadpool": {
"min_workers": 1,
"max_workers": 50,
"queue_capacity": 100
}
}
load_balancer_port - This is the port that the load balancer is binded to
queue_capacity - this is the maximum request queue capacity for the server or threadpool
min_workers - this is the minimum number of workers a thread pool can have while running
max_workers - this is the maximum number of workers a thread pool can have while running
Claude was used throught this project for:
- system design decisions
- code generation and debugging
The conversation log can be found here: https://claude.ai/share/fb225a07-cb8a-47d3-bc3c-59cb44ecc14a
All AI generated output was reviewed, verified, and tested by me. The final implementation is my own.
https://gobyexample.com/worker-pools https://go.dev/tour/concurrency/1 https://medium.com/@asgrr/lock-and-rlock-in-golang-74ca6ce95783 https://medium.com/@yashbatra11111/building-a-reverse-proxy-in-go-with-custom-middleware-5b137340992c https://codingchallenges.fyi/challenges/challenge-load-balancer/ https://dev.to/jaiminbariya/load-balancing-algorithms-with-examples-4bn5 https://github.com/teejays/load-balancer/tree/master https://dev.to/vivekalhat/building-a-simple-load-balancer-in-go-70d https://www.geeksforgeeks.org/system-design/load-balancing-algorithms/ https://gobyexample.com/command-line-arguments https://aws.amazon.com/what-is/load-balancing/#what-are-the-types-of-load-balancing--1v2lmja https://aws.amazon.com/compare/the-difference-between-the-difference-between-application-network-and-gateway-load-balancing/ https://www.sohamkamani.com/golang/http-client/ https://tutorialedge.net/golang/parsing-json-with-golang/ https://medium.com/@AlexanderObregon/signal-handling-in-go-applications-b96eb61ecb69 https://praella.com/blogs/shopify-news/scaling-go-services-with-worker-pools-lessons-from-shopify-and-beyond https://gobyexample.com/tickers