A health endpoint helps an orchestrator decide whether to restart a process or send it traffic. Those are different questions. Liveness asks whether the process should remain running; readiness asks whether it can accept the work routed to it.
Keep liveness simple
A liveness route should avoid calling every dependency. If PostgreSQL has a brief outage, restarting every healthy application instance can make recovery worse. Readiness can check required dependencies with a short timeout and a bounded query, but it should not perform expensive work or expose internal diagnostics publicly.
In Axum, keep handlers small and return stable status codes. Do not include environment variables, connection strings, or detailed error messages in the response. If checks are asynchronous, apply timeouts and classify each dependency’s importance. An optional AI provider should not necessarily make a core content API unready.
Align probes with shutdown behavior
On termination, stop accepting new work, mark readiness false, allow in-flight requests to finish within a deadline, then close pools. Configure the container’s grace period to match this lifecycle. Probe intervals and failure thresholds should account for expected startup time and temporary load.
Test cold startup, a required dependency outage, an optional dependency outage, and graceful shutdown. Confirm the probe response matches what the load balancer does. A health endpoint is useful when it leads to the right operational action, not when it simply returns
200Give liveness and readiness separate jobs
Axum assembles routes with a Router and serves them with an async runtime. In the example below, the handler uses a static string, so the endpoint only demonstrates that the HTTP process is responding. A readiness handler may need to check a dependency. Give each check a deadline, and return a deliberate service-unavailable status for the work it cannot accept. Axum framework documentation
DevShareHub's Rust executor registers a GET /health route separately from POST /execute. A probe that returns HTTP 200 for /health can be part of a container check without executing a program. Test the healthy and dependency-failed states for your own readiness route and document which probe the deployment uses to route new traffic. Kubernetes liveness and readiness probes
Worked example
This targets Axum 0.8 with Tokio runtime/network features enabled. Request /health locally; distinguish process liveness from readiness to serve database-dependent requests.
rustuse axum::{routing::get, Router}; #[tokio::main] async fn main() { let app = Router::new().route("/health", get(|| async { "ok" })); let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); }




Community
Discussion
Loading comments…