Skip to content

Designing a load balancer and reverse proxy from scratch

Notifications You must be signed in to change notification settings

Recedivies/rece-lb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rece-LB

Building a HTTP load balancer and reverse proxy from scratch written in Go.

Features

  • Random
  • Round Robin
  • Least Connection
  • Passive health check at configurable intervals
  • Active health check
  • Config support using json

Running it

Start multiple instances of server.py

# create a virtual env (optional)
python3 -m venv venv
source venv/bin/activate

# install flask
pip install flask

# make multiple servers
./run.sh

Start the loadbalancer

go run main.go

Spam the loadbalancer with requests

for i in {1..20}; do curl -i 127.0.0.1:8080; done

To kill all the instances of the servers

./clear.sh

Config

port

The port to the run the load balancer on.

servers

A list of servers we want to forward requests to.

algorithm

Algorithm for load balancing. Can be Random, RoundRobin, or LeastConnection .

health_check_type

Defines the type of health check you want to perform on your server. Can be passive or active (active health check is by default).

health_check_interval

Time interval in seconds to perform health check on servers.

Sample Config

{
  "port": 8080,
  "servers": [
    "http://localhost:5001",
    "http://localhost:5002",
    "http://localhost:5003",
    "http://localhost:5004",
    "http://localhost:5005"
  ],
  "algorithm": "Random",
  "health_check_type": "passive",
  "health_check_interval": 5
}

About

Designing a load balancer and reverse proxy from scratch

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published