
Axum Rate Limiting With Tower Governor and Redis Explained
Limit requests per client in Axum with a small middleware, then see when to switch to tower_governor or a Redis counter. Includes fixed windows, token buckets and 429 responses.
Everything you need to level up your coding skills.

Limit requests per client in Axum with a small middleware, then see when to switch to tower_governor or a Redis counter. Includes fixed windows, token buckets and 429 responses.

Load settings from environment variables into a typed struct at startup, fail fast on missing values, give safe defaults for the rest and keep secrets out of logs and Debug output.

Protect an Axum service from slow and oversized requests: TimeoutLayer, DefaultBodyLimit, header limits and what a reverse proxy should add on top.

Find where a Rust program allocates with a profiler or an allocation counter, then remove the hot ones: reuse buffers, borrow, pre-size and avoid format in loops.

Set rustc and Clippy lint levels in the [lints] table of Cargo.toml, inherit them across a workspace with workspace.lints and handle priority for groups.

Each layer of an application should speak its own error type. Convert at the boundary with From, keep causes for logs and map to HTTP codes only at the edge.

Group statements so they succeed or fail together with pool.begin. Learn commit, the automatic rollback on drop, error handling with the question mark and lock behavior.

Handle HTML forms and multipart file uploads in Axum 0.8: Form, Multipart, size limits, content type checks, safe filenames and streaming to disk.

Tower defines Service and Layer, the two traits behind every Axum middleware. See poll_ready, call, how layers wrap services and when to write one.

Add behavior around every request with Tower layers, or write your own with axum middleware from_fn. See the order layers run in and when to pick each form.

tokio::time::timeout drops the future when time runs out, which is not the same as stopping the work behind it. Learn what actually gets cancelled.

In argument position impl Trait is a generic, in return position it hides one concrete type, and dyn Trait is for several. Here is how to pick in each place.
We send one email when a new post is published. No spam.