Skip to content

rahul07bagul/Design-Load-Balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Load Balancer (C++)

Overview

This project implements a Load Balancer System for managing backend servers efficiently. It supports automatic server scaling, health checking, and request distribution using a Round-Robin, Least Connection, Resource Based Strategy. The system is built using C++ with gRPC for inter-service communication and Crow for HTTP-based management.

C++ CMake Windows Linux

Features

  • Load Balancing: Distributes incoming requests among active backend servers.
  • Server Management: Allows dynamic addition and removal of backend servers.
  • Health Monitoring: Periodically checks server health and replaces unhealthy instances.
    • Scale Up: Adds a new server if CPU usage exceeds 80%
    • Failure Handling: Adds a new server if an existing one is unresponsive.
    • Scale Down: Removes servers when they are no longer needed to optimize resource usage.
  • Admin API: Provides gRPC-based server administration.
  • HTTP API: Enables interaction with the system using RESTful endpoints.

Design Patterns

  • Strategy Pattern: Supports different load-balancing algorithms (e.g., Round-Robin) that can be easily added or configured, making the system scalable.
  • Factory Pattern: Provides an abstraction for OS-specific process management, enabling support for both Windows and Linux to create, terminate processes, and retrieve resource details.

Demo

Design

Architecture

Design

Class Diagram

Design

Installation & Setup

Prerequisites

Package Installation

  • Download vcpkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
  • Install gRPC and protobuf
.\vcpkg install grpc:x64-windows
.\vcpkg install protobuf:x64-windows
.\vcpkg integrate install

Running the Load Balancer

./load_balancer --backend-path ./server --port 50050 --min-servers 2 --max-servers 5 --start-port 50051

Running the Health Checker

./health_checker 127.0.0.1:50050

API Endpoints

HTTP API (Crow)

  • GET /api/status - Returns a list of active servers.
  • POST /api/add_server - Adds a new backend server.
  • POST /api/remove_server - Removes a server by ID.

Contributing

Feel free to contribute by submitting pull requests or feature requests.

Demo Images

Design Design

About

Load Balancer System using C++ and gRPC.

Topics

Resources

License

Stars

Watchers

Forks

Contributors