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
- Host: GitHub
- URL: https://github.com/kunalvirwal/Velocity
- Owner: kunalvirwal
- Created: 2024-09-16T23:12:30.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-01T13:04:35.000Z (over 1 year ago)
- Last Synced: 2025-01-11T18:45:42.129Z (over 1 year ago)
- Topics: go, golang, health-check, least-connections, load-balancer, reverse-proxy, roundrobin, routing, yaml-configuration
- Language: Go
- Homepage:
- Size: 5.73 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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

Round Robin Algorithm tests

Least Connections Algorithm tests

Made with β€οΈ by Kunal