Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Python builds (pip, venv, requirements.txt)

What is gunicorn and how many workers should you run?

BeginnerConceptPython builds (pip, venv, requirements.txt)
Answer

Short answer

Gunicorn is a production WSGI server for Python web apps (Flask, Django). It starts a master process that manages several worker processes, each handling requests, so the app serves many users at once and restarts crashed workers automatically. A common starting point is (2 × CPU cores) + 1 workers.

Example

gunicorn -w 5 -b 0.0.0.0:8000 myproject.wsgi:application      # Django on 2 cores
gunicorn -w 4 -k gthread --threads 4 -b 0.0.0.0:8000 app:app  # threads for I/O-heavy apps
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app        # FastAPI (ASGI)

Or a config file:

# gunicorn.conf.py
bind = "0.0.0.0:8000"
workers = 4
timeout = 60
accesslog = "-"

Workers in Kubernetes

Pods often get small CPU limits (e.g. 500m). Running 9 workers in a half-core pod just wastes memory. Many teams run 2–4 workers per pod and scale with more pods (HPA).

Common issue

WORKER TIMEOUT → a request took longer than --timeout (default 30s). Fix the slow call first; raise the timeout only if it's legitimately long.

What to say in the interview

"Gunicorn is a pre-fork WSGI server: a master plus N worker processes. On VMs I start from 2×cores+1; in Kubernetes I keep workers modest per pod and scale horizontally, sending logs to stdout."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Python apps: pip, venv & requirements.txt

More on Python builds (pip, venv, requirements.txt)