Skip to content

Uttkarsh-raj/Go-Load-Balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go-Load-Balancer

Go-Load-Balancer is a lightweight load-balancer built in Golang. It includes implementations for round-robin static routing and least connection dynamic routing, offering a simple yet powerful solution for distributing network traffic efficiently.

Table of Contents

Table of Contents
  1. About The Project
  2. Built With
  3. Getting Started
  4. Usage
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

Go-Load-Balancer is a lightweight load-balancer built in Golang. It supports round-robin static routing and least connection dynamic routing, making it an ideal tool for evenly distributing traffic across multiple servers.

Load Balancer

A load balancer is a network device or software that distributes incoming network traffic across multiple servers. This helps ensure that no single server becomes overwhelmed, improving reliability, availability, and scalability.

Static Routing

Static routing refers to a predetermined, fixed path that network traffic follows. It doesn't change unless manually adjusted, making it simple but inflexible.

Round Robin

Round Robin is a static routing method where requests are distributed in a cyclic manner. Each server in the pool receives an equal number of requests in turn, regardless of server load or capacity.

Go-Load-Balancer-Round-Robin-Demo.mp4

Dynamic Routing

Dynamic routing adjusts the path of network traffic based on real-time conditions, such as server load or network congestion. This helps optimize performance and resource utilization.

Least Connection

The Least Connection method is a dynamic routing strategy that directs new requests to the server with the fewest active connections. This helps balance the load more evenly, especially in environments with varying server capacities or request processing times.

NOTE: Here, I have set up 3 demo servers where the sleep time simulates computation time, varying for each server based on its processing power and input data. As seen in the response, the 2nd server, with the shortest sleep time (representing faster computation), handles more requests due to its quicker processing.

Go-Load-Balancer-Least-Connection-Demo.mp4

Built With

  • Golang - An open-source programming language.

(back to top)

Getting Started

To get started with go-load-balancer, follow these steps:

  1. Install Golang: Download and install Golang from the official website.
  2. Set Up Your Workspace: Create a new directory for your project and set your GOPATH environment variable to point to this directory.
  3. Initialize Your Project: Inside your project directory, run:
    go mod init github.com/your-username/go-load-balancer
    
  4. Run without Debugging:
    go run main.go
    

Installation

  1. Clone the repo:
    git clone https://github.com/Uttkarsh-raj/go-load-balancer
    
  2. Install the packages:
    go mod tidy
    

(back to top)

Routes

  • POST "/addServer"
    • Request as:
      • body
        {
          "address":"https://server_address.com"
        }
        
    • Response as:
      • Success: Respective output.
        {
          "message": "Server added successfully",
          "success": true
        }
        
      • Failure: "message" : Error.
        {
          "message": "error: Unable to add the server",
          "success": false
        }
        
  • DELETE "/delete"
    • Request as:
      • body
        {
          "address":"https://server_address.com"
        }
        
    • Response as:
      • Success: Respective output.
        {
          "message": "Server deleted successfully",
          "success": true
        }
        
      • Failure: "message" : Error.
        {
          "message": "error: Server does not exists",
          "success": false
        }
        
  • ANY "/path_for_the_servers"
    • Request as:
      • body as required by the servers being handled by the load-balancer
    • Response as:
      • Success: Respective output.
      • Failure: "message" : Error.

Usage

The Go-Load-Balancer project offers a flexible solution for load balancing across multiple servers. It supports:

  1. Web Application Scaling: Distribute user requests across multiple web servers to handle increased traffic and ensure smooth performance.
  2. API Gateway: Balance incoming API requests among backend services, improving reliability and response time.
  3. Database Load Management: Distribute queries across multiple database instances to prevent any single instance from being overwhelmed.

Screenshots



Contributing

Contributions make the open-source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project.
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature).
  3. Commit your Changes (git commit -m 'Add some AmazingFeature').
  4. Push to the Branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

(back to top)

License

This project is licensed under the MIT License, a permissive open-source license that allows for the use, modification, and distribution of this software. It grants users the freedom to use the software for any purpose, including commercial purposes, as long as the original copyright and license notice is included. See the LICENSE file for more information. (back to top)

Contact

Uttkarsh Raj - GitHub

Project Link: https://github.com/Uttkarsh-raj/go-load-balancer

(back to top)

Acknowledgments

(back to top)

About

Go-Load-Balancer is a lightweight load-balancer built in Golang. It includes implementations for round-robin static routing and least connection dynamic routing. πŸ”— https://uttkarsh.hashnode.dev/what-is-a-load-balancer-a-comprehensive-golang-tutorial-for-building-your-own

Topics

Resources

License

Stars

Watchers

Forks