Skip to content

pushkar-gr/Deston

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deston

A High-Performance, Rust-based Layer 4 (TCP) & Layer 7 (HTTP) Load Balancer.

Rust License: GPL v3 Build

Deston is a lightweight, asynchronous load balancer built in Rust. It is designed for speed and flexibility, offering dual support for transport-layer (L4) and application-layer (L7) load balancing. Built on top of tokio and hyper, Deston handles high-concurrency traffic with ease.


🏗️ Architecture

Deston sits between clients and your backend infrastructure, intelligently distributing traffic based on your configuration. It supports both raw TCP streams (L4) for maximum throughput and HTTP (L7) for header-aware routing.


✨ Key Features

  • Dual-Mode Operation: Switch between Layer 4 (TCP) and Layer 7 (HTTP) modes via a simple config change.
  • Asynchronous & Non-Blocking: Built on tokio to handle thousands of concurrent connections efficiently.
  • Header Injection (L7): Automatically injects X-Forwarded-For and Host headers for backend transparency.
  • Pluggable Algorithms: Choose the distribution strategy that best fits your traffic patterns.
  • Session Affinity: Built-in support for IP Hashing to ensure clients stick to specific servers.

🧠 Load Balancing Algorithms

Deston supports three core algorithms, configurable in config.toml:

Algorithm Key Description
Round Robin round_robin Distributes requests sequentially across all available servers. Ideal for stateless backends with equal capacity.
Weighted Round Robin weighted_round_robin Respects the weight parameter. Servers with higher weights receive proportionally more traffic. Perfect for heterogeneous server clusters.
IP Hashing ip_hashing Uses the client's IP address to determine the server. Ensures the same client always reaches the same server (Session Persistence).

🚀 Quick Start

Prerequisites

  • Rust: Version 1.70 or higher.
  • Cargo: Included with Rust installation.

Installation

  1. Clone the repository:
git clone https://github.com/pushkar-gr/Deston.git
cd Deston
  1. Build the project:
cargo build --release
  1. Run the Load Balancer:
cargo run --release

⚙️ Configuration

Deston is configured via a config.toml file in the root directory.

Example Configuration

[load_balancer]
address = "127.0.0.1"   # The IP Deston will bind to
port = 8080             # The port Deston will listen on
algorithm = "round_robin" # Options: round_robin, weighted_round_robin, ip_hashing
layer = "L7"            # Options: L4, L7

# Backend Server 1
[[server]]
address = "127.0.0.1"
port = 3000
max_connections = 1000
weight = 3              # Higher weight = more traffic (if using weighted_round_robin)

# Backend Server 2
[[server]]
address = "127.0.0.1"
port = 3001
max_connections = 1000
weight = 1

Configuration Parameters

[load_balancer]

  • layer: L4 (TCP) or L7 (HTTP). Defaults to L4 if unspecified.
  • algorithm: The strategy for picking servers. Case-insensitive (e.g., RoundRobin, ip_hashing).
  • address: The host address to bind (e.g., 0.0.0.0 for public access).
  • port: The listening port.

[[server]]

  • address/port: The location of the backend instance.
  • max_connections: Hard limit on concurrent connections forwarded to this server.
  • weight: Used only by weighted_round_robin to bias traffic distribution.

📂 Project Structure

  • src/config: TOML parsing and configuration management.

  • src/load_balancer:

  • layer4.rs: Raw TCP stream forwarding implementation.

  • layer7.rs: HTTP request parsing and forwarding via hyper.

  • algorithm/: Implementation of routing logic (Static, Hashing, etc.).

  • src/server: Backend server connection handling and metric tracking.


🤝 Contributing

Contributions are welcome!

  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.

About

A L7 & L4 load balancer built using rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages