A for-fun Load Balancer written in Golang.
- Load Balancing (It balances your load)
- Weighted Priority Queue (Based on pending requests)
- Configuable via API requests
- Passive Healthchecks
- Down Detection
Requirements
- Golang 1.16+
Instructions
- Checkout this repository.
- Run
go build .
in the project directory. - Execute
./go-balance
to startup the server. - Using the configuration API below, register hosts, and adjust settings.
- Profit 💰
The load balancer accepts configuration requests on port 4501. You can cofigure the following with the configuration API:
- Health check frequency is seconds. (Default: 60s)
- Configure number of retries before failing a request. (Default: 5s)
- Configure the delay between retries. (Default: 1000ms)
- De/Register Hosts/Nodes to the load balancer.
The /config
endpoint is responsible for global settings on the load balancer.
hcFrequency
: Health check freqency in seconds.
retries
: Number retries before failing request.
retryDelay
: Number of milliseconds between retries.
{
"hcFrequency": 30,
"retries": 2,
"retryDelay": 200
}
Sample curl command
curl -X POST -H "Content-Type: application/json" --data "{\"hcFrequency\":30, \"retries\":5, \"retryDelay\":200}" localhost:4501/config
The /register
endpoint is responsible to assigning host/nodes to the load balancer.
{
"url": "https://<HOST>:<PORT>"
}
Sample curl command
curl -X POST -H "Content-Type: application/json" --data "{\"url\":\"http://localhost:3000\"}" localhost:4501/register
The /deregister
endpoint is responsible to removing host/nodes from the load balancer.
{
"url": "https://<HOST>:<PORT>"
}
Sample curl command
curl -X POST -H "Content-Type: application/json" --data "{\"url\":\"http://localhost:3000\"}" localhost:4501/deregister