https://github.com/rahul07bagul/design-load-balancer
Load Balancer System using C++ and gRPC.
https://github.com/rahul07bagul/design-load-balancer
cpp design-patterns grpc load-balancer multithreading server system-design
Last synced: 3 months ago
JSON representation
Load Balancer System using C++ and gRPC.
- Host: GitHub
- URL: https://github.com/rahul07bagul/design-load-balancer
- Owner: rahul07bagul
- License: mit
- Created: 2025-02-19T23:18:26.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-03-26T21:27:55.000Z (3 months ago)
- Last Synced: 2025-03-26T22:28:36.899Z (3 months ago)
- Topics: cpp, design-patterns, grpc, load-balancer, multithreading, server, system-design
- Language: C++
- Homepage:
- Size: 1.16 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.## 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
## Architecture
## Class Diagram
## Installation & Setup
### Prerequisites
- C++17 or later
- gRPC and Protobuf
- Crow HTTP frameowrk
- CMake
- [Click here to view instructions.txt](https://github.com/rahul07bagul/load-balancer-cpp/blob/main/instructions.txt)
### Package Installation
- Download vcpkg
```shell
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
```
- Install gRPC and protobuf
```shell
.\vcpkg install grpc:x64-windows
.\vcpkg install protobuf:x64-windows
.\vcpkg integrate install
```
### Running the Load Balancer
```shell
./load_balancer --backend-path ./server --port 50050 --min-servers 2 --max-servers 5 --start-port 50051
```
### Running the Health Checker
```shell
./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

