An open API service indexing awesome lists of open source software.

https://github.com/kunalvirwal/Velocity

A load balancer with TCP health checks, routing algorithms, and yaml based configuration
https://github.com/kunalvirwal/Velocity

go golang health-check least-connections load-balancer reverse-proxy roundrobin routing yaml-configuration

Last synced: 10 days ago
JSON representation

A load balancer with TCP health checks, routing algorithms, and yaml based configuration

Awesome Lists containing this project

README

          

```
####################################################
# _ __ __ _ __ #
# | | / /__ / /__ ____(_) /___ __ #
# | |/ / -_) / _ \/ __/ / __/ // / #
# |___/\__/_/\___/\__/_/\__/\_, / #
# /___/ #
####################################################
```

# About

This is a project to create a load balancer in Golang that can manage local and global servers and containers named Velocity. It should have Round Robin and Least Connections balancing algorithms and should be configurable via yaml.
This project was started in my 3rd semester and is an ambitious and a great learning project.
It currently has Health Checks and removal of servers for if the server is down is configurable via yaml file to route requests to multiple servers for different applications implementing uniquely different balancing algorithms for each one.

# Features of a LoadBalancer:

βœ…: Implemented
🚧: Under active development

βœ… It should be software based
βœ… It should be written in Golang ( use Go routines for parallelism)
βœ… It should be able to manage all local and global servers and containers
βœ… Lightweight

## Phase I :Learning Project
βœ… It should be configurable via a config file :Done
βœ… It should have:
1) round robin (normal and weighted) :Done
2) Least Connections :Done
βœ… Health Checks for if the server is down add or remove it from rotation [ βœ…TCP connections or HTTPS pings or health endpints ] :Done
🚧 REST API interface for Hot Addition and removal of servers
βœ… Proper Logging and monitoring ( access logs like forwards, healthchecks, request drops, status codes,... 🚧can store into a database like a mongo alpine container)
Rate limiting [ IP address and end point ]

## 🚧Phase II :Prod level orchestration
look up auto scaling
IP blacklisting
Request queuing
Request processing time out
Circuit breaker
Exponential backoff
It could also have:
1) Sticky Round Robin
2) IP/Url Hash

## 🚧Phase III :Service level monitoring
Dashboard for load visualization or can integrate Prometheus
Reverse proxy Graceful Shutdown
Timeouts

# File structure
```
Load_Balancer/
β”œβ”€β”€ cmd/
β”‚ └── main.go # Entry point for the application
β”œβ”€β”€ internal/
β”‚ β”œβ”€β”€ balancer/
β”‚ β”‚ β”œβ”€β”€ balancer.go # Core load balancing logic (round robin, least connections, etc.)
β”‚ β”‚ β”œβ”€β”€ round_robin.go # Different balancing strategies (Round Robin, etc.)
β”‚ β”‚ └── least_connections.go # Different balancing strategies (Least Connections, etc.)
β”‚ β”œβ”€β”€ config/
β”‚ β”‚ └── config.go # Configuration loading and parsing logic
β”‚ β”œβ”€β”€ healthcheck/
β”‚ β”‚ └── healthcheck.go # Health checking logic for backends
β”‚ β”œβ”€β”€ server/
β”‚ β”‚ β”œβ”€β”€ server.go # Server logic, like adding, removing, and selecting servers
β”‚ β”‚ └── baremetal_server.go # Server handling for bare metal servers
β”‚ └── utils/
β”‚ β”œβ”€β”€ utils.go # Utility functions like Error Handling etc.
β”‚ └── logger.go # Utility functions like logging
β”œβ”€β”€ 🚧pkg/
β”‚ └── api/
β”‚ └── handler.go # API handler to manage the load balancer (optional)
β”œβ”€β”€ test/
β”‚ β”œβ”€β”€ test_servers.go/ # A go test server that return 200 status code on /.
β”‚ β”œβ”€β”€ sample.env # Sample configuration file for the test servers
β”‚ └── Dockerfile # Dockerfile for the test server
β”œβ”€β”€ config.yaml # Configuration file for backends, strategies, etc.
β”œβ”€β”€ go.mod # Go module file
β”œβ”€β”€ go.sum # Go dependencies checksum file
└── README.md # Project documentation
```

To Run the Load Balancer

`go run .`

For Hot Realoading while development use:

`CompileDaemon -build="go build -o main ." -command="./main"`

For starting testing server on localhost after creating .env:

`go run ./test/test_servers.go`

For starting testing server in docker on port 8001:

`docker run --rm -e PORT=80 -e DURATION=0.1 -p 8001:80 kunalvirwal/go_server`

For testing the load balancer use:

`bombardier -c 125 -n 1000 http://localhost:8000`

Tip: To test multi-redirection modify your `/etc/hosts` to have many custom domain names to mimic different services and point them all to Velocity port 8000 at localhost

# Testing and Examples


Logging

![Logging](./Readme_Assets/Logging.png)


Round Robin Algorithm tests

![Round Robin Algorythm tests](./Readme_Assets/RoundRobin.png)


Least Connections Algorithm tests

![Least Connections Algorithm tests](./Readme_Assets/LeastConnections.png)


Made with ❀️ by Kunal