Home > Mobile >  Why we need to setup AWS and POSTgres db when we deploy our app using Heroku?
Why we need to setup AWS and POSTgres db when we deploy our app using Heroku?

Time:10-11

I'm building a web api by watching the youtube video below and until the AWS S3 bucket setup I understand everything fine. But he first deploy everything locally then after making sure everything works he is transferring all static files to AWS and for DB he switches from SQLdb3 to POSgres.

django portfolio

I still don't understand this part why we need to put our static files to AWS and create POSTgresql database even there is an SQLdb3 default database from django. I'm thinking that if I'm the only admin and just connecting my GitHub from Heroku should be enough and anytime I change something in the api just need to push those changes to github master and that should be it.

Why we need to use AWS to setup static file location and setup a rds (relational data base) and do the things from the beginning. Still not getting it!

Can anybody help to explain this ? Thanks

CodePudding user response:

Databases

There are several reasons a video guide would encourage you to switch from SQLite to a database server such as MySQL or PostgreSQL:

  1. SQLite is great but doesn't scale well if you're expecting a lot of traffic
  2. SQLite doesn't work if you want to distribute your app accross multiple servers. Going back to Heroky, if you serve your app with multiple Dynos, you'll have a problem because each Dyno will use a distinct SQLite database. If you edit something through the admin, it will happen on one of this databases, at random, leading to inconsistencies
  3. Some Django features aren't available on SQLite

SQLite is the default database in Django because it works out of the box, and is extremely fast and easy to use in local/development environments for prototyping.

However, it is usually not suited for production websites. Additionally, while it can be tempting to store your sqlite.db file along with your code, for instance in a git repository, it is considered a bad practice because your database can contain sensitive data (such as passwords, usernames, emails, etc.). Hence, a strict separation between your code and data is a good practice.

Another way to put it is that your code and your data have different lifecycles. You want to be able to edit data in your database without redeploying your code, and update your code without touching your database.

Even if you can remove public access to some files through GitHub, this is not a good practice because when you work in a team with multiple developpers, developpers may have access to the code but not the production data, because it's usually sensitive. If you work with 5 people and each one of them has a copy of your database, it means the risk to lose it or have it stolen is 5x higher ;)

Static files

When you work locally, Django's built-in runserver command handles the serving of static assets such as CSS, Javascript and images for you.

However, this server is not designed for production use either. It works great in development, but will start to fail very fast on a production website, that should handle way more requests than your local version.

Because of that, you need to host these static files somewhere else, and AWS is one place where you can do that. AWS will serve those files for you, in a very efficient way. There are other options available, for instance configuring a reverse proxy with Nginx to serve the files for you, if you're using a dedicated server.

As far as I can tell, the progression you describe from the video is bringing you from a local, development enviromnent to a more efficient and scalable production setup. That is to be expected, because it's less daunting to start with something really simple (SQLite, Django's built-in runserver), and move on to more complex and abstract topics and tools later on.

  • Related