For a long time Gunicorn+Uvicorn was the default setup for running FastAPI in production. However, I recently came across a blog post saying:
In the meantime, this combination of Gunicorn and Uvicorn is no longer needed, as Uvicorn now also handles worker management itself
I haven't found any other sources to verify this statement. Beside this, the official documentation only mention that the tiangolo/uvicorn-gunicorn-fastapi base Docker image is deprecated, but say nothing about Gunicorn+Uvicorn setup itself
So:
fastapi run --workers 4 main.py and gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker now?No. Since Uvicorn 0.30 (released May 2024), it's no longer necessary. That version introduced a built-in multi-process supervisor that supports:
--workers to launch multiple processes
Automatic restart of crashed workers
Request limits via --limit-max-requests for leak mitigation
Shortly after, FastAPI’s creator deprecated the tiangolo/uvicorn-gunicorn-fastapi Docker image, stating:
Now that Uvicorn supports managing workers with
--workers, including restarting dead ones, there's no need for Gunicorn.
Starting with FastAPI 0.110, the fastapi run CLI is just a thin wrapper around this new Uvicorn supervisor. So the official recommendation is now plain uvicorn or fastapi run for most use cases.