Skip to content

Deployment

This section covers deploying a FasterAPI application to production — from containers to cloud platforms to bare-metal servers.

Pages

Topic What you learn
Docker Dockerfile, multi-stage builds, docker-compose
systemd Service Service unit file, auto-start, journald logging
Gunicorn + Uvicorn Multi-process worker pooling, production config
HTTPS — Let's Encrypt Free TLS certificates with Certbot and Nginx
Nginx & Traefik Reverse proxy, TLS termination, load balancing
Cloud Services AWS, GCP, Azure deployment options
Kubernetes Manifests, health checks, rolling updates

ASGI servers

FasterAPI is an ASGI application; you need an ASGI server to run it:

Server Notes
uvicorn Recommended. Lightweight, production-ready.
hypercorn Supports HTTP/2 and HTTP/3.
daphne Django Channels' server; ASGI-native.
granian Rust-based; very fast.
pip install uvicorn[standard]

# Development
uvicorn main:app --reload

# Production (multiple workers)
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4

Hypercorn

pip install hypercorn

hypercorn main:app --bind 0.0.0.0:8000 --workers 4

Hypercorn supports HTTP/2 with TLS:

hypercorn main:app --bind 0.0.0.0:443 \
  --keyfile key.pem --certfile cert.pem

Daphne

pip install daphne

daphne -b 0.0.0.0 -p 8000 main:app

Number of workers

A rule of thumb for CPU-bound workloads: 2 × CPU cores + 1. For I/O-bound APIs, experiment with higher values.

uvicorn main:app --workers $(( 2 * $(nproc) + 1 ))

For Python 3.13 with SubInterpreterPool, a single uvicorn worker can leverage multiple CPU cores — see Concurrency & Parallelism.

Environment variables

Always configure the application through environment variables in production. See Settings & Environment Variables.

Health checks

Expose a /health endpoint for load balancers and container orchestrators:

@app.get("/health")
async def health():
    return {"status": "ok"}

Next steps