title: NGINX + Flask, without Gunicorn?
body: <p>I am new to this, but by comparing the code of gunicorn with flask/werkzeug, I fail to understand the real benefit of inserting gunicorn between nginx and flask. Would like to get some expert opinions on this.</p>
  <p>For what I understand so far, it boils down to comparing gunicorn with werkzeug's dev server. In short, I fail to understand why werkzeug's server is called a dev server, while gunicorn is considered prod ready. The argument for choosing gunicorn over werkzeug that I can think of:</p>
  <ol>
  <li>Performance. Gunicorn is based on prefork model, while werkzeug can spin off a thread or process on the fly for each request. But Stevens had a comparison in his UNP book, and prefork was not a clear winner in his tests. Spinning off a thread (not process) on linux should be fairly cheap, without the need to handle the pre-forked process pool. So for CPU bound services, the python GIL makes werkzeug's threading model less attractive, but for IO bound services, werkzeug should be good enough?</li>
  <li>Gunicorn supports gevent/eventlet/tornado, while werkzeug does not. But since asyncio is becoming a native in python 3, these green threads libraries seem less crucial?</li>
  <li>Security? again I am no expert on this, but nginx seems a good defender already? Besides, gunicorn does not seem to provide extra protection in this regard, compared to werkzeug's dev server.</li>
  <li>SSL. Flask and werkzeug server does not seem to handle this. But nginx can handle this already, so flask does not need to?</li>
  <li>Unix socket. Werkzeug's server does not seem to handle unix socket. So if nginx need to forward traffic to backend with unix sockets, either because it's the only way or because it's the most efficient way, then it seems a good argument for gunicorn.</li>
  </ol>
  <p>Are the reasons above valid? What are the other reasons?</p>
  <p>Btw, I have read <a href="https://stackoverflow.com/questions/20766684/what-benefit-is-added-by-using-gunicorn-nginx-flask">SO post 1</a> and <a href="https://stackoverflow.com/questions/38982807/are-a-wsgi-server-and-http-server-required-to-serve-a-flask-app">SO post 2</a> but they do not seem to fully answer my questions yet.</p>