I'm entirely uninitiated to the world of web development, and only have a tentative grasp on Django and web development through the test server it works through.

From the guide I'm reading, the author turns to using Nginx once he starts working on site deployment, because Django is "not designed for real-life workloads." What does that mean, and why doesn't it? In terms of justification for using Gunicorn, the author remarks:

Do you know why the Django mascot is a pony? The story is that Django comes with so many things you want: an ORM, all sorts of middleware, the admin site…​ "What else do you want, a pony?" Well, Gunicorn stands for "Green Unicorn", which I guess is what you’d want next if you already had a pony…​

Well and good, but I don't really know what the two are doing for the server. I know for web developers this is like asking what multiplication is to a maths professor, so please excuse the naivety. In your please keep in mind I have almost no knowledge of web development other than what I've thus far learned from this guide, doing my best to understand as much as I can for the previously entirely uninitiated (I'm from a computational programming background).


This doc mentions

DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests.

So I guess that's the part where "Django is not designed for real-life workloads", and we need something reliable and well tested in production.

When a request arrives at your server, it is passed to the web server that could handle multiple requests at once. When the web server determines the request should be processed by your application, the request is then passed to application server. The application server translates the request to some Python objects that can be used by Django web application (through WSGI specification). Then the application server calls the app code in your project with the request Python objects, and gets the response Python objects from your application. The application server then translates the response back to the HTTP response and sends back to the web server. The web server finally returns the response to the caller.

Nginx is one of the web server, and Gunicorn is one of the valid WSGI application server.

enter image description here

Other than dispatching the request and calls the app properly, Nginx handles lots of requests coming in at once and saves CPU/memory resources comparing with the Python code, and Gunicorn runs a pool of worker processes/threads to execute the app code, so they are both considered as improving the performance.

| improve this answer | |

I have no experience with Django but I do have experience with Nginx. Nginx is a proxy server that can route http traffic based on rules like path matching. A lot of web applications use nginx as a backend to serve the static content and then route requests to backend services.

Again, I don't have much knowledge about Django but I think you're instructor could have been talking about a development server inside Django that is not suitable for production load and that after you compile the application to static content use nginx to serve that content.

| improve this answer | |
  • What is path matching? I hear you that you’re not familiar with Django so I anticipate you may not be able to answer this, but why wouldn’t it be suitable for production load, and what exactly do you mean by production load? – genjong Nov 22 at 4:47
  • What I mean by production load is because Django is "not designed for real-life workloads." real-life workloads. – Sam Orozco Nov 22 at 4:48

When author says that Django can't handle real workloads, they most likely refer specifically to Django's built-in webserver.

When you run Django in development environment, you can use it to test things out, but a proper webserver is a fairly complex piece of software and requires very specific competences to build. Moreover, there is no real reason for the people behind Django to also spend time making a fully fleshed-out webserver: it is much easier to build an interface for an existing one.

Nginx is a professionally made workhorse of a server. It is feature-rich and is built to handle production workloads. Most apps use a server like that on the front to handle niche responsibilities like caching, redirection, forming headers, compression etc.

So, now, Gunicorn. Gunicorn is a WSGI server. Broadly speaking, it facilitates communication between a variety of webservers and a variety of frameworks through a standardized interface. Plus it handles additional tasks, like load-balancing and maintaining instances of your app alive, so you don't have to.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.