Prerequisites and Production Environment Setup
I've deployed a bunch of Axum apps since 0.8 dropped. Here's what I learned getting burned by production over the last few months.
Why Production Will Break Your Beautiful Local Setup
Your Axum app works perfectly on localhost. It starts in 100ms, handles requests beautifully, and the logs are pristine. Then you deploy it and everything goes to shit.
Production is where your beautiful local setup goes to die. I've lost entire weekends debugging why my app crashes with "Connection refused" when it runs fine in development. The problem? Docker's networking doesn't resolve localhost
- you need to use the service name or 0.0.0.0
. Axum itself is solid but the surrounding ecosystem will kick your ass.
Real production deployments involve shit that doesn't happen locally: network timeouts, database connection pool exhaustion, memory limits that kill your process, and load balancers that decide your health checks are lying. Yeah, Discord and Dropbox use Rust for performance. Doesn't mean deployment stops being a pain in the ass.
The Shit You Actually Need (Not the Tutorial Stuff)
System Requirements
You need Linux. I've tried Windows containers - don't. Any recent Ubuntu or Debian works fine. Docker that isn't ancient. Minimum 512MB RAM, but budget 2GB because your app will eat way more memory than you expect. Learned this after my app kept crashing every few hours with no clear logs. Spent a weekend thinking it was a Rust memory leak or some database connection issue. Finally found buried in the system logs that Docker was killing it for memory usage. Classic.
Rust Toolchain
Install current stable Rust. Don't get fancy with nightly - production deployment is complicated enough. Use multi-stage Docker builds because compiling Rust apps takes forever and the final binary is tiny compared to the build environment.
Development Environment
Your local environment should mirror production or you'll spend hours debugging differences. Use Docker Compose locally - I don't care if you prefer running PostgreSQL natively, containers save your sanity. The dotenv crate works for local env management, but don't use .env files in production.
Database Integration
Most production Axum apps need PostgreSQL with SQLx for compile-time query verification. This is brilliant when it works and absolutely infuriating when it doesn't. Migrations break SQLx compile-time checks in weird ways, and you'll spend an hour figuring out offline mode exists.
Redis works great for caching until your connection pool settings are fucked and requests start hanging with no clear error messages.
External Dependencies
Third-party APIs will fail at the worst possible time. Set aggressive timeouts - I default to 10 seconds max. The reqwest crate with connection pooling prevents the "too many open files" nightmare. Consider circuit breaker patterns for failing services and retry strategies for transient failures.
Configuration That Won't Screw You Later
Never hardcode anything. Seriously. Use environment variables for everything deployment-specific. The config crate is decent for structured configuration, but envy is simpler for deserializing environment variables into structs.
Secrets Management
Environment variables visible to ps aux
are not secrets management. Use Kubernetes secrets if you're on K8s, Docker secrets for Swarm, or cloud provider solutions like AWS Secrets Manager. I've seen production API keys in git history - don't be that person.
Health Checks
You need /health
and /ready
endpoints. Load balancers and orchestrators depend on these. Make them actually check your dependencies - a health check that always returns 200 is useless. But don't make health checks expensive or your load balancer will kill healthy instances during traffic spikes. Consider implementing liveness vs readiness checks properly if using Kubernetes.
The rest of this guide covers the details that will save you from 3am debugging sessions. The Twelve-Factor App methodology has more production deployment principles that actually matter, if you're into that sort of thing.