Skip to main content
Deploying Axum applications requires attention to performance, reliability, and security considerations. This guide covers production deployment strategies.

Running with Hyper

Axum uses Hyper under the hood. The standard way to run an Axum app:
Binding to 0.0.0.0 makes your server accessible from outside the host machine. Use 127.0.0.1 for local-only access.

Graceful shutdown

Handle shutdown signals gracefully to avoid dropping in-flight requests:

Basic graceful shutdown

1

Handle SIGTERM and SIGINT

Listen for shutdown signals from the operating system or container orchestrator.
2

Stop accepting new requests

The server stops accepting new connections but continues processing existing ones.
3

Wait for in-flight requests

Allow existing requests to complete normally.
4

Clean shutdown

Close all connections and exit gracefully.

With timeout protection

Prevent requests from hanging during shutdown:

Advanced serving with Hyper

For more control over the HTTP server, use Hyper’s low-level API:
  • Custom connection handling logic
  • Per-connection state or middleware
  • Fine-grained control over HTTP/1.1 vs HTTP/2
  • Custom TLS configuration
  • Performance optimization for specific use cases

Configuration management

Use environment variables and configuration files:

Logging and observability

Implement comprehensive logging for production:

Performance optimization

Connection pooling

Use connection pools for databases:

Response compression

Body size limits

Docker deployment

Create an optimized Dockerfile:
Multi-stage builds keep your final image small by excluding build dependencies.

Kubernetes deployment

Example Kubernetes manifest:

Health checks

Implement health and readiness endpoints:

Security best practices

Always validate and sanitize user input. Never trust data from external sources.

HTTPS/TLS

For TLS termination, use a reverse proxy (nginx, Caddy) or cloud load balancer rather than handling TLS in your Axum app.

Security headers

Rate limiting

Monitoring and metrics

Monitor key metrics: request rate, error rate, response time (latency), and saturation (resource usage).