Skip to content

Kayleexx/apex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apex TCP Proxy

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.


Features

  • 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.toml and updates backends and load balancing in real-time.
  • Async and High Performance: Built with Tokio, fully asynchronous for low-latency forwarding.

Architecture


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.toml automatically update backend addresses and the load balancer.
  • Load balancing is implemented as round-robin: requests cycle through available healthy backends.

Configuration

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.

Running Apex

# 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:8081 by default.
  • Open another terminal to test:
curl http://127.0.0.1:8081

Logs & Output

Example Log Snippet

2025-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

Load Balancing Behavior

  • 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.

Notes & Tips

  • Ensure backends are running before sending requests to the proxy.
  • For debugging, check logs for alive: true/false to see which backends are used.
  • Config reload works in real-time, so you can add/remove backends on the fly.

Dependencies

  • Rust 1.80+
  • Tokio (async runtime)
  • tracing & tracing-subscriber (logging)
  • notify (config file watching)

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages