A Simpler and Faster Rust Framework for Many Protocols on a Single Port
— Aex: Rethinking Network Framework Design from the TCP Layer Up
📌 Project Repository
https://github.com/Free-Web-Movement/aex
🧭 Table of Contents
- Introduction
- Why Aex?
- Core Philosophy
- Architecture Overview
- HTTP Design (Simplified)
- Multi-Protocol Design
- Performance Benchmark (HTTP Comparison)
- Router Design (Trie)
- Middleware & Validation
- Code Examples (HTTP + Multi-Protocol)
- Real Use Cases
- Conclusion
1. Introduction
Modern backend systems are no longer just HTTP servers.
They must handle:
- HTTP APIs
- WebSocket
- P2P communication
- Custom binary protocols
Traditional solutions:
- Multiple ports
- Reverse proxy layers
- Microservices split
➡️ This creates complexity and overhead.
2. Why Aex?
Most Rust frameworks:
| Framework | Model |
|---|---|
| Axum | HTTP-first |
| Actix | HTTP-first |
| Warp | HTTP-first |
Aex:
TCP-first, Protocol-agnostic
3. Core Philosophy
✅ One Port
All protocols share a single port.
✅ Full Control
You control TCP, parsing, routing.
✅ Performance First
No heavy abstraction layers.
4. Architecture Overview
Client
↓
TCP Listener
↓
Protocol Detection
↓
┌───────────────┬───────────────┬───────────────┐
│ HTTP │ P2P │ Custom Binary │
└───────────────┴───────────────┴───────────────┘
↓
Router → Middleware → Handler
5. HTTP Design (Simplified)
Traditional frameworks:
Request → Hyper → Layers → Router → Handler
Aex:
Request → Parser → Router → Handler
Simplified HTTP Routing
router.get("/user/:id", |ctx| async move {
let id = ctx.params.get("id").unwrap();
ctx.response.body = format!("User {}", id);
true
});
6. Multi-Protocol Design
Core idea:
ONE PORT → MULTIPLE PROTOCOLS
Protocol Detection Example
if is_http(&buffer) {
handle_http(ctx).await;
} else if is_p2p(&buffer) {
handle_p2p(ctx).await;
} else {
handle_custom(ctx).await;
}
7. Performance Benchmark (HTTP Comparison)
Internal Aex Benchmark
| Stage | QPS |
|---|---|
| Initial | ~750 |
| Optimized | ~3900 |
| Peak | ~4300+ |
Estimated Comparison
| Framework | QPS (approx) | Notes |
|---|---|---|
| Axum | 5k–15k | Hyper-based |
| Actix | 10k–20k | Highly optimized |
| Aex | 4k+ (early) | Not fully optimized yet |
⚠️ Important
Aex performance is still improving, but:
It trades some HTTP peak for multi-protocol flexibility + control
8. Router Design (Trie)
Supports:
- Static
- Param
- Wildcard
Structure:
(root)
├── user
│ ├── :id
└── file
└── *
9. Middleware & Validation
Example:
middleware(|ctx| async move {
if ctx.headers.get("token").is_none() {
ctx.response.status = 401;
return false;
}
true
});
10. Code Examples
10.1 Simple HTTP
router.get("/hello", |ctx| async move {
ctx.response.body = "Hello Aex".into();
true
});
10.2 Multi-Protocol Example
async fn handle_connection(buffer: Vec<u8>) {
if is_http(&buffer) {
handle_http(buffer).await;
} else if is_p2p(&buffer) {
handle_p2p(buffer).await;
} else {
handle_binary(buffer).await;
}
}
10.3 Custom Protocol Example
fn is_p2p(buf: &[u8]) -> bool {
buf.starts_with(b"P2P")
}
11. Real Use Cases
🔹 Blockchain Node
- HTTP API + P2P in one port
🔹 IoT Gateway
- Devices + API unified
🔹 High Performance Backend
- Binary + HTTP mixed
12. Conclusion
Aex is not just a web framework.
It is a network framework
Key Advantages
- One port architecture
- Protocol flexibility
- Full control
- Clean routing
Final Thought
If you need:
- Multi-protocol system
- High control
- Custom networking
➡️ Aex is a strong foundation.
Top comments (0)