Skip to content

An HTTP load-balancer built using Go and Gin, supporting TLS encryption, backend health checks, and metrics monitoring.

Notifications You must be signed in to change notification settings

lokeshllkumar/load-balancer

Repository files navigation

http-load-balancer

An HTTP load balancer built using Go and the Gin framework, with support for multiple balancing strategies(round-robin, least connections, and sticky sessions).

Features

  • Balancing algorithms
    • Round-robin
    • Least connections
    • Sticky sessions
  • Backend Health Checks - Monitors backend health at regular intervals
  • TLS Encryption - Secure communication between the clients and the load balancer
  • Metrics Monitoring - Tracks incoming requestsand backend performance

Setup and Installation

  • Prerequisites
    • Go 1.20+
    • OpenSSL(to generate certificates)
  • Clone the Repository
git clone https://github.com/lokeshllkumar/load-balancer.git
cd load-balancer
  • Install the Required Dependencies
go mod tidy
  • Generate TLS Certificates
    • Create a directory called certs to store the certificate
    • Generate an RSA key
    openssl gen rsa -out key.pem 2048
    • Generate a CSR file to create a Certificate
    openssl req -new -key key.pem -out server.csr
    
    • Generate the Self-Signed Certificate
    openssl x509 -req -days 365 -in server.csr -signkey key.pem -out cert.pem
    • Verify the Certificate
    openssl x509 -in cert.pem -text -noout
  • Build the Project
go build -o load-balancer .
  • Run the server
./load-balancer

Usage

  • Health Check Endpoint
    • Check if the server is running
    curl https://localhost:843/health --insecure
  • Add a Backend Server
    • Add a backend server dynamically
    curl -X POST https://localhost:8443/api/backends -d '{"url": "https://backend3:8082"}' -H "Content-Type: application/json" --insecure
  • List All Backends
    curl https://localhost:8443/api/backends --insecure

Load Balancing Strategies

  • Round Robin
    • Distributes requests evenly across all available backends.
  • Least Connections
    • Directs traffic to the backend with the fewest active connections.
  • Sticky Sessions
    • Ensures requests from the same client are directed to the same backend.

About

An HTTP load-balancer built using Go and Gin, supporting TLS encryption, backend health checks, and metrics monitoring.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published