1

I am working my way to deploy my django app on a Linux Server. Encountered with various problems and want someone to clarify that for me. I searched for days but the answer I found are either too broad or faded away from topic.

1) According to django docs, it is inefficient to serve static files locally. Does that means that all the static files including html,css,js files should be hosted on another server?

2) I have an AWS S3 bucket hosting all my media files, can I use that same bucket (or create a new bucket) to host my static files if above answer is yes. If so, is that efficient?

3) According to search, in order for django to scale horizontally, it should be a stateless app, does it means that I also have to host my database on a different location than my own Linux server ?

Paaksing
  • 432
  • 1
  • 4
  • 17

1 Answers1

1

1) It is completely fine to host your staticfiles on the same server as your django application however to serve said files you should use a web server such as NGINX or Apache. Django was not designed to serve static data in a production environment. Nginx and Apache on the other hand do great job at it.

2) You can definitely host your static and media files inside an S3 bucket. This will scale a lot better than hosting them on a single server as they're provided by a separate entity, meaning that no matter how many application servers you're running behind a load balancer, all of them will be requesting staticfiles from the same source. To make it more efficient you can even configure AWS' CloudFront which is Amazons CDN (content delivery network).

3) Ideally your database should be hosted on a separate server. Databases are heavy on resources therefore hosting your database on the same server as your application may lead to slowdowns and sometimes outright crashes. Scaling horizontally, you'd be connecting a lot of application servers to a single database instance; effectively increasing the load on that server.

All of the points above are relative to your use case and resources. If the application you are running doesn't deal with heavy traffic - say a few hundred hits a day - and your server has an adequate amount of resources (RAM, CPU, storage) it's acceptable to run everything off a single box.

However if you're planning to accept tens of thousands of connections every day it's better to separate the responsibilities for optimum scalability. Not only it makes your application more efficient and responsive but it also makes your life easier in the long run when you need to scale further (database clustering, nearline content delivery, etc).

TL;DR: you can run everything off a single server if it's beefy enough but in the long run it'll make your life harder.

Hevlastka
  • 1,878
  • 2
  • 18
  • 29
  • Hello, thanks for replying, where should I host my database (separate from my app) ? On another linux machine ? or something else? – Paaksing May 20 '20 at 20:06
  • Yeah, ideally you'd host it on a separate server (bare metal or VM). You can look at db hosted services that are provided by GCE or AWS however they usually come at a price markup due to the maintenance benefits they provide. – Hevlastka May 20 '20 at 20:54
  • If it can run linux then it'll work. Hell, you can even install it on a raspberry pi but I wouldn't recommend doing that in production. Especially for a database server! :) Keep in mind that if you get more traffic you will eventually have to upgrade as database resources will eventually become a bottleneck. – Hevlastka May 20 '20 at 21:07