Part 9 · 1 chapters · ~8 min
In Production: What Python Is Paired With
The classic Django production stack (Nginx or a load balancer, Gunicorn or Uvicorn workers, PgBouncer, Postgres, Celery with Redis or RabbitMQ, Sentry and OpenTelemetry), worker sizing, static files, settings for production, Docker images, and Kubernetes specifics.
15
The stack around a Django service
code
# production settings that matter
DEBUG = False
ALLOWED_HOSTS = ["api.bank.example"]
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SESSION_COOKIE_SECURE = CSRF_COOKIE_SECURE = True
DATABASES["default"]["CONN_MAX_AGE"] = 60
DATABASES["default"]["DISABLE_SERVER_SIDE_CURSORS"] = True # required with PgBouncer transaction pooling
# container command
gunicorn config.asgi:application -k uvicorn.workers.UvicornWorker -w 4 --timeout 30 --graceful-timeout 25 \
--max-requests 2000 --max-requests-jitter 200 # recycle workers to contain slow leaks
python manage.py check --deploy # Django's own production checklistWHAT PYTHON IS PAIRED WITH IN PRODUCTION
the classic Django stack
swipe the figure sideways, or tap expand for full screen
1/5
the proxy
Nginx or a cloud load balancer terminates TLS and buffers slow clients, which matters a lot for Gunicorn's sync workers (Prodstack course part 1). WhiteNoise or a CDN serves static files.
TLS and slow-client bufferingWhiteNoise or a CDN for static