Insights from Our Experts
How to host your Django project to production server
Django’s practical design and ease of use make it a highly popular choice for web development applications. It wouldn't be wrong to say Django is a better-evolved framework for web development than its counterparts. Django offers many advantages such as better documentation, compatibility with SEO practices, scalability, and security that makes it a top preference among startups for web development.
Once you have successfully developed and demonstrated your Django project, the very next step is to deploy it to the production server- the final step to take your project live. Django supports numerous ways to deploy the project to production. You can use your preferred web server, database, proxy, and so on.
Read also: When should you choose Django Framework
What are the elements of a Django Production Server Architecture?
Below shown is a Django Production Server Architecture. There could be many iterations of the architecture. The below one covers all the entities and requirements of the Production Server setup.
Apache, nginx, lighttpd, cherokee
mod_python, mode_wsgi, Gunicorn, uwsgi, FastCGI
MySQL/ Postgres/ Other databases
A Web server uses the client/server model and the World Wide Web's Hypertext Transfer Protocol ( HTTP ) to serve the files from Web pages to Web users. We can use any of Apache, Nginx, or Lighttpd. But when we choose a web server, we need to select an appropriate submodule compatible with it from mod_python, mode_wsgi, Gunicorn, uWSGI, FastCGI. For example, we can use apache with mod_python or mode_wsgi, Nginx with uWSGI, or Gunicorn.
Some tasks will take a very long time to finish and a user need not to wait for its result. In such cases, we can make the background task to work in a different thread or maybe in a different server altogether. We can make use of celery here.
Celery - Celery is an asynchronous task/job queue based on distributed message passing. Celery is written in Python, but the protocol can be implemented in any language.
Workers - Used to process the messages sent by Celery. we can set multiple workers.
Supervisor - It is a client/server system that allows its users to monitor and control several processes on UNIX-like operating systems. We can start/ stop Celery using this.
Broker - We have to run some brokers on servers to process our tasks. We can use RabbitMQ or Redis for this
When our project is hosted, we need to monitor it using some tools to check its performance, its error logs, and user interactions. Following are some of the tools that we can utilize:
Graphite - Graphite provides real-time visualization and storage of numeric time-series data on an enterprise level.
Statsd - A network daemon that runs on the Node.js platform and listens for statistics, like counters and timers, sent over UDP or TCP, and sends aggregates to one or more pluggable backend services (e.g., Graphite).
Sentry - logging - Sentry is a modern error logging and aggregation platform.
New Relic - A software analytics tool suite used by developers, ops, and software companies to understand how your applications are performing in development and production.
Our live project needs continuous development and deployment. So, we need some deployment automation tool that simplifies our deployment. One of them is Fabric - Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.