DEV Community

Alex Spinov
Alex Spinov

Posted on

Axum Has a Free Rust Web Framework — Memory Safe and Blazingly Fast

Axum is built on Tokio and Tower by the Tokio team. Type-safe extractors, zero-cost abstractions, and the performance only Rust can deliver.

Why Rust for Web?

Node.js: ~15K req/s. Go: ~150K req/s. Rust (Axum): ~300K+ req/s. With zero garbage collection pauses and memory safety guaranteed at compile time.

What You Get for Free

use axum::{routing::get, Router, Json, extract::Path};
use serde::{Serialize, Deserialize};

#[derive(Serialize)]
struct User {
    id: u32,
    name: String,
}

async fn get_user(Path(id): Path<u32>) -> Json<User> {
    Json(User { id, name: "Alice".into() })
}

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/user/:id", get(get_user));

    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}
Enter fullscreen mode Exit fullscreen mode

Type-safe extractorsPath, Query, Json, State — compiler validates everything
Tower middleware — reuse the entire Tower ecosystem (timeouts, rate limiting, tracing)
Tokio runtime — async I/O, the most battle-tested Rust async runtime
No macros required — unlike Actix or Rocket, Axum uses plain functions
WebSocket support — built-in
Compile-time errors — wrong extractor type? Compiler tells you, not a runtime crash

Extractors (The Killer Feature)

async fn create_user(
    State(db): State<Database>,           // shared state
    Json(payload): Json<CreateUserRequest>, // request body
) -> Result<Json<User>, AppError> {
    let user = db.create_user(payload).await?;
    Ok(Json(user))
}
Enter fullscreen mode Exit fullscreen mode

Each parameter is extracted and validated by the compiler. Wrong type = compile error, not runtime error.

Performance

  • 300,000+ req/s for JSON responses
  • <1ms latency at p99 under load
  • 2-5MB memory for a typical web server
  • Zero GC pauses — Rust has no garbage collector

Quick Start

cargo new myapp
cd myapp
cargo add axum tokio serde serde_json
cargo add tokio --features full
Enter fullscreen mode Exit fullscreen mode

If you need maximum performance and reliability — Axum is the Rust framework the Tokio team built for production.


Need web scraping or data extraction? Check out my tools on Apify — get structured data from any website in minutes.

Custom solution? Email spinov001@gmail.com — quote in 2 hours.

Top comments (0)