Docker Django NGINX Postgres build with scaling

4/29/2020

I have worked mostly with monolithic web applications over the years and have not spent very much time looking at Django high-availability scaling solutions.

There are plenty of NGINX/Postgres/Django/Docker builds on hub.docker.com but not one that I could find that would be a good starting point for a scalable Django web application.

Ideally the Docker project would include:

  • A web container configuration that easily allows adding new web containers to web app
  • A database container configuration that easily allows adding new database shards
  • Django microservice examples would also be a plus

Unfortunately, I do not have very much experience with Kubernetes and Docker swarms.

If there are none, I may make this my next github.com project.

Thank you in advance.

-- Mark
django
docker
high-availability
kubernetes
postgresql

1 Answer

4/29/2020

That is a very broad request. It depends on many factors:

What is the performance requirement?

Make sure, you really need that kind of scaling. In most cases, a single good server with docker-compose can handle your needs. If you want to reduce risk of downtime, create 2 servers, add a load balancer in between them and extract shared services like DB or Caching into another Service and have both server instances use them.

How do you want to run your applications?

Docker-Compose:

Checkout https://github.com/pydanny/cookiecutter-django on how to do it with docker-compose on a single server.

Kubernetes:

Django is quite good to run in Kubernetes, I am running several applications on Kubernetes. The issue with that is, you need to setup all other services properly (redis, DB, ElasticSearch, etc.). Each of those services run independently of your main Django app and need to be connected through libraries like haystack or python-redis.

Heroku & others

There are also providers like Heroku that offer a lot the auto scaling for a price. If price is less of a concern, go with these solutions because they are very easy to setup and maintain.

How scalable should your DB be?

If you are trying to setup your own DB cluster across different servers/regions, you will spend a lot of time building and maintaining it. I would recommend, use DB services like AWS RDS. They do this for you with easy setup and maintenance. You can configure how scalable it should be. It costs some money, but it's the least effort solution.

-- Özer S.
Source: StackOverflow