How do you deploy FastAPI to production?

Answer

Production FastAPI deployment options: Docker + Gunicorn + Uvicorn workers: the standard pattern. Dockerfile: base on tiangolo/uvicorn-gunicorn-fastapi image or build custom. Run: gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000. Kubernetes (AKS/GKE/EKS): containerize, create Deployment + Service + Ingress. Use Horizontal Pod Autoscaler. Serverless containers: Cloud Run, Azure Container Apps, AWS App Runner — zero config, scale to zero. Serverless functions: AWS Lambda with Mangum adapter (converts ASGI to Lambda handler). Checklist: disable debug mode, set workers proportional to CPU cores, configure trusted hosts, add rate limiting, enable HTTPS via reverse proxy (Nginx/Traefik), configure structured logging (JSON for log aggregation), add health check endpoint (/health), run as non-root user in Docker.