GoBalance

command module
v0.0.0-...-99d94e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 5 Imported by: 0

README

GoBalance: A Go-based Load Balancer

Welcome to GoBalance, a lightweight and customizable load balancer built in Go. This project demonstrates my proficiency in Go and distributed systems, showcasing my ability to develop robust backend solutions. GoBalance supports multiple load balancing strategies, including Round Robin, Weighted Round Robin, and Sticky Round Robin, and includes health checking functionality for backend servers.

Features

  • Round Robin: Distributes incoming requests evenly across all available servers.
  • Weighted Round Robin: Allows servers to receive traffic proportionally based on their assigned weights.
  • Sticky Round Robin: Ensures that a client is consistently routed to the same server across requests, enabling session persistence.
  • Health Checks: Periodically checks the health of backend servers to ensure that only healthy servers receive traffic.

Getting Started

Prerequisites
  • Go 1.19 or later
  • Basic understanding of distributed systems and load balancing concepts
Installation
  1. Clone the repository:

    git clone https://github.com/ParhamMootab/GoBalance.git
    cd GoBalance
    
    
  2. Build the project:

    go build -o gobalance .
    
    
  3. Run the load balancer:

    ./gobalance
    
    
Usage

When you run the GoBalance executable, you'll be prompted to configure the load balancer:

Choose a Load Balancing Strategy:

1 for Round Robin 2 for Weighted Round Robin 3 for Sticky Round Robin Enter Server URLs:

Add the URLs of the backend servers that GoBalance should distribute traffic to. If you select Weighted Round Robin, you'll also need to specify the weight for each server. Set Health Check Interval:

Specify the interval (in seconds) at which GoBalance should perform health checks on the backend servers. Start the Load Balancer:

GoBalance will start listening on port 8080, distributing incoming traffic based on the chosen strategy.

Example
$ ./gobalance

***********************************************************
*                                                         *
*      _____       ____        _                          *
*     / ____|     |  _ \      | |                         *
*    | |  __  ___ | |_) | __ _| | __ _ _ __   ___ ___     *
*    | | |_ |/ _ \|  _ < / _`  | |/ _` |  _ \ / __/ _ \    *
*    | |__| | (_) | |_) | (_| | | (_| | | | | (_|  __/    *
*     \_____|\___/|____/ \__,_|_|\__,_|_| |_|\___\___|    *
*                                                         *
***********************************************************

Enter the load balancing strategy 
(1 for Round Robin, 2 for Weighted Round Robin, 3 for Sticky Round Robin): 1
Enter the server url (Enter 'D' if you've entered all urls): http://localhost:8081
Enter the server url (Enter 'D' if you've entered all urls): http://localhost:8082
Enter the server url (Enter 'D' if you've entered all urls): d
Enter the health check interval in seconds: 10

Load Balancer started at: 8080
Project Structure
  • main.go: The entry point of the application, where the CLI is implemented.
  • LoadBalancer/: Contains the core logic for the load balancer, including different load balancing strategies and health checks.
  • Server/: Manages the server object and reverse proxy setup.
Why GoBalance?

This project is a testament to my skills in:

  • Go Programming: Leveraging Go's concurrency model and standard library to build performant and reliable systems.
  • Distributed Systems: Understanding of load balancing strategies, fault tolerance, and high availability.
  • CLI Development: Building user-friendly command-line tools to configure and manage complex systems.
Contributing

Contributions are welcome! If you have ideas for new features or improvements, feel free to fork the repository and submit a pull request.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
sample_servers
server1 command
server2 command
server3 command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL