A lightweight, high-performance TCP reverse proxy in Rust with dynamic backend health checks and round-robin load balancing. Apex ensures requests are forwarded only to healthy backends.
- TCP Proxy: Forward TCP traffic from a listening port to multiple backend servers.
- Round-Robin Load Balancing: Requests are distributed evenly across all healthy backends.
- Dynamic Health Checks: Periodically checks backend availability and updates routing automatically.
- Hot Config Reloading: Detects changes to
config.tomland updates backends and load balancing in real-time. - Async and High Performance: Built with Tokio, fully asynchronous for low-latency forwarding.
Client → [Apex TCP Proxy] → [Healthy Backend(s)]
- The proxy listens on a port (default
8081) and forwards traffic to healthy backend servers. - Backend health is checked periodically (default every 5 seconds).
- Only healthy backends are used for request forwarding.
- Supports hot config reload: changes in
config.tomlautomatically update backend addresses and the load balancer. - Load balancing is implemented as round-robin: requests cycle through available healthy backends.
Create a config.toml file:
backend_addrs = ["127.0.0.1:9000", "127.0.0.1:9001"]- Add or remove backend addresses as needed.
- The proxy automatically reloads this file when modified.
# Run your backend(s) first, e.g.:
python3 -m http.server 9000
python3 -m http.server 9001
# Run the proxy
cargo run- The proxy listens on
127.0.0.1:8081by default. - Open another terminal to test:
curl http://127.0.0.1:80812025-10-03T05:49:40 INFO apex: Loaded backend addresses: ["127.0.0.1:9000", "127.0.0.1:9001"]
2025-10-03T05:49:40 INFO apex: Proxy listening on 127.0.0.1:8081
2025-10-03T05:50:05 INFO apex::proxy_utils: Health check 127.0.0.1:9000 => alive: true
2025-10-03T05:50:05 INFO apex::proxy_utils: Health check 127.0.0.1:9001 => alive: false
2025-10-03T05:50:43 INFO apex: Accepted connection from 127.0.0.1:45688
2025-10-03T05:50:43 INFO apex: Connected to backend: 127.0.0.1:9000
2025-10-03T05:50:43 INFO apex: Forwarding data between 127.0.0.1:45688 and 127.0.0.1:9000
- Round-robin ensures even distribution across healthy backends.
- Backends marked unhealthy by health checks are skipped automatically.
- When backends recover, they are re-added to the rotation automatically.
- Ensure backends are running before sending requests to the proxy.
- For debugging, check logs for
alive: true/falseto see which backends are used. - Config reload works in real-time, so you can add/remove backends on the fly.
- Rust 1.80+
- Tokio (async runtime)
- tracing & tracing-subscriber (logging)
- notify (config file watching)
MIT License