Skip to content

pi-rate14/vestri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vestri (Simple-LB)

A lightweight and configurable HTTP Layer 7 Load Balancer and Reverse Proxy written in Go.

Problem Statement

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.

Solution

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.

Features

  • 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 weight parameter, 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.yaml file.

Tech Stack

  • Language: Go (1.18+)
  • Routing & Proxying: net/http/httputil ReverseProxy
  • Configuration: Go YAML (gopkg.in/yaml.v2)
  • Logging: Logrus (github.com/sirupsen/logrus)

Usage

1. Define Configuration

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: 4

2. Run the Load Balancer

Start the application pointing to the config file and defining a port:

go run cmd/vestri/main.go --port 8080 --config ./example/config.yaml

Vestri will start on localhost:8080/api/v1 and handle request dispatching and health checking automatically!

3. Demo Server

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

Walkthrough (Internal Lifecycle)

  1. Each request is made to the loadbalancer running on localhost:8080.
  2. The request path is matched to find the mapped service.
  3. All the active server replicas for this service are queried.
  4. The Load Balancing Strategy for this service is evaluated (defaults to Round Robin).
  5. The request is proxied to the chosen replica based on the underlying LB strategy.

TODOs & Future Features

  • 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

About

Fault Tolerant Load Balancer written in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages