A lightweight and configurable HTTP Layer 7 Load Balancer and Reverse Proxy written in Go.
When scaling web applications horizontally, there's a need to efficiently distribute incoming network traffic across a group of backend servers (replicas). Without a robust load balancer, individual servers could become overwhelmed while others remain idle, leading to poor resource utilization, high latency, and decreased availability.
Vestri provides a simple, highly-configurable load balancing solution. It acts as a reverse proxy that sits in front of your backend servers and routes client requests across all capable servers to maximize speed and capacity utilization while ensuring that no one server is overworked.
- Path-based Routing: Match incoming request paths to specific backend services.
- Load Balancing Strategies:
- Round Robin: Distributes requests sequentially across active servers.
- Weighted Round Robin: Distributes requests sequentially based on a configured
weightparameter, ideal for heterogeneous environments where some servers have more capacity than others.
- Active Health Checking: Continuously monitors the health of backend server replicas. If a server goes down, Vestri automatically halts traffic to it, and resumes routing once it's healthy again.
- YAML Configuration: Easily configure your services, routes, and replicas via a simple
config.yamlfile.
- Language: Go (1.18+)
- Routing & Proxying:
net/http/httputilReverseProxy - Configuration: Go YAML (
gopkg.in/yaml.v2) - Logging: Logrus (
github.com/sirupsen/logrus)
Create a config.yaml file to define the services to balance:
services:
- name: "service1"
strategy: "WeightedRoundRobin"
matcher: "/api/v1"
replicas:
- url: "http://127.0.0.1:8081"
metadata:
weight: 2
- url: "http://127.0.0.1:8082"
metadata:
weight: 4Start the application pointing to the config file and defining a port:
go run cmd/vestri/main.go --port 8080 --config ./example/config.yamlVestri will start on localhost:8080/api/v1 and handle request dispatching and health checking automatically!
A quick demo server is provided to spin up dummy backends on custom ports to test your load balancer:
go run cmd/demo/main.go -port 8081- Each request is made to the loadbalancer running on
localhost:8080. - The request path is matched to find the mapped service.
- All the active server replicas for this service are queried.
- The Load Balancing Strategy for this service is evaluated (defaults to Round Robin).
- The request is proxied to the chosen replica based on the underlying LB strategy.
- Error Handling Optimizations
- Optimize Weighted Round Robin Logic
- Add more matching and routing rules
- Put requests in a queue if no servers are available using a configurable timeout