Overview of Django deployment options
Deployment seems to be an area a lot of Django developers struggle with. There are a ton of options out there and every tutorial seems to advocate for a specific way. The official Django docs intentionally (and perhaps wisely) does not go too deep into the topic and as a result a lot of new Django developers struggle with the topic of deployment.
In this article I try to help you identify which “ways” are available to you and what requirements you should consider when choosing your deployment method. Deployment is by itself a very big topic. It includes a lot of smaller topics such as:
- Where to host (serve) your code?
- Where to host your database?
- Where to store your static and media files?
- How to ensure the security of your application?
- and so on.
In this article I am focusing mainly on the ways you can “host” your Django web app and its database.
Generally speaking, you have two options available to you: PaaS or IaaS.
PaaS (Platform as a Service) is a website that offers to host your code for you. You don’t need to bother about configuring the server and maintaining it. Same thing with the database. You don’t need to manually install it on a virtual machine and maintain it. They do it for you. In exchange, you pay a monthly fee. Almost all PaaS solutions have a free tier where you can test things out. Usually the pricing starts small and then increases as your website grows and attracts more users and traffic. Examples of PaaS are Heroku and PythonAnywhere.
IaaS (Infrastructure as a Service) is basically a fancy term for providers that offer you a Linux machine on the cloud. You then have to set up the sever, install your database, make sure the routing works, and also keep it maintained. The cloud instances are usually very cheap and if you know what you are doing you can extract a good amount of performance out of them before you are forced to upgrade to beefier machines or bigger disk space. You can also do fancy things like creating a Kubernetes cluster or rolling out a Docker swarm. And since you have done everything on a bare-bone Linux machine, you can easily move your code to another IaaS if you wish. Examples of IaaS are Digital Ocean, and Google Cloud. There are many more and some IaaS providers have even started offering PaaS solutions.
Which one to choose?
In my opinion, the choice comes down to three factors:
Speed of deployment: For most people and projects, it is faster to deploy an app on a PaaS. The setup is minimal and is usually well-documented.
Costs: While PaaS and IaaS start more or less around the same price (and you can usually get a free trial in both categories), PaaS becomes more expensive as your website grows.
Maintenance: The extra cost of PaaS is offset by the fact that you do not need to do any maintenance on the servers. While in a IaaS solution you are expected to do routine maintenance on the servers to keep them running smoothly.
So basically you need to assess your skills and what you are willing to sacrifice in order to deploy your app.
If you have a team, and there are people on the team that can focus on sysadmin stuff, and you anticipate rapid growth for your app, go with a IaaS solution.
However, if you are a solo developer, don’t feel 100% comfortable doing server configuration and maintenance, and don’t mind paying to free up your time and energy to focus on your app, go with a PaaS solution.
I hope this helped you orient yourself a little in the deployment jungle. Best of luck to you!