The difference lies in the type of server you are using and how it interacts with the underlying application.
GUNICORN
is a WSGI
framework which, di per se, is not compatible with Fastapi
, since Fastapi
uses the ASGI
standard (i.e. asynchronous). This means that Gunicorn
will have to use some layer of abstraction (uvicorn.workers.UvicornWorker
) in order to communicate with the asynchronous calls.
On the other hand, Uvicorn
is an ASGI
framework which has been developed with asynchronous in mind and can interact directly with the underlying Fastapi
application.
That being said, you are spawning in both cases 4 workers that will run in parallel and independently, serving the requests that arrive to the server. The way they serve the requests and handle the underlying application, is server specific, as mentioned above.
Sources:
What is the difference between Uvicorn and Gunicorn+Uvicorn?