A High-Performance, Rust-based Layer 4 (TCP) & Layer 7 (HTTP) Load Balancer.
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.
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.
- Dual-Mode Operation: Switch between Layer 4 (TCP) and Layer 7 (HTTP) modes via a simple config change.
- Asynchronous & Non-Blocking: Built on
tokioto handle thousands of concurrent connections efficiently. - Header Injection (L7): Automatically injects
X-Forwarded-ForandHostheaders 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.
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). |
- Rust: Version 1.70 or higher.
- Cargo: Included with Rust installation.
- Clone the repository:
git clone https://github.com/pushkar-gr/Deston.git
cd Deston
- Build the project:
cargo build --release
- Run the Load Balancer:
cargo run --release
Deston is configured via a config.toml file in the root directory.
[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
[load_balancer]
- layer:
L4(TCP) orL7(HTTP). Defaults toL4if 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.0for 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_robinto bias traffic distribution.
-
src/config: TOML parsing and configuration management. -
src/load_balancer: -
layer4.rs: Raw TCP stream forwarding implementation. -
layer7.rs: HTTP request parsing and forwarding viahyper. -
algorithm/: Implementation of routing logic (Static, Hashing, etc.). -
src/server: Backend server connection handling and metric tracking.
Contributions are welcome!
- Fork the project.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.