Skip to content

Deploying a Database

Gingertonic edited this page May 19, 2021 · 8 revisions

Deploying a database can seem intimidating at first, partly because there are many options and partly because many of those options take your credit card details! Here are a few recommendations to investigate...

As we've seen before, Heroku is a good option for freebie server hosting. They offer a Postgres add-on.

AWS

The cheapest way to handle a small database on AWS would be to add one manually to your EC2 instance. For small projects this should serve you just fine as proof of concept with no additional costs over your EC2 billing. If your home computer can handle it at the same time as other activity without panicking, so can your EC2 instance (check your AMI specs of course!). You could even use a docker-compose configuration quite easily without making changes. You may want to strongly consider adding validations in your code to check your database size regularly and delete old data to avoid hitting your storage limits.

When working at a company however there is a good chance that you'll be working with a managed database service. At time of writing, AWS has 15 managed database options covering 9 types of database! A few of the most popular are:

Amazon RDS offers 6 services that can be used to manage a variety of relational databases including PostgreSQL
DynamoDB is AWS' serverless NoSQL offering. This video walkthrough is an excellent starting point for connecting to a DynamoDB using Amplify.

Once you've made a MongoDB Atlas cluster, you can connect to it from nigh on anywhere.
Find our own walkthrough here

FaunaDB is a very user friendly, serverless, collection-document database service. Fauna uses it's own query language, FQL. For a walkthrough on adding it to a Netlify-deployed app, give this a go. Netlify Functions actually harnesses the same AWS Lambda service as Amplify just with some limitations.

Google's Firebase has a popular and interesting real time database offering. For more info, see their own introduction.


A note on AWS

AWS have lots of free training material. If you're not sure where to start I recommend this quickstart overview. If you are interested in more AWS training, their Foundations course is free and a good primer for their huge array of other courses including Database Offerings.

The Free Tier can get you quite a long way so make sure to weigh up the free tier offerings when considering your options.

They have various options for deploying full stack web applications. The most appropriate to consider at this stage are:

Amazon's lightest weight Virtual Private Server option is ideal for smaller scale applications. You may need to draw on other AWS services to complete your setup. For a PostgreSQL setup, check out their documentation on connecting to a PostgreSQL database. There are costs involved but they are low and predictable. AWS Budgets can help plan and ease your mind in that respect.

eb is a one-stop-shop that makes connecting to other AWS services smooth and contained. Come this way for a guide on adding a relational database to your EB setup.


Test vs Dev vs Production

It is highly likely that your development database will not be the same as your production one eg. using a local database just as we have used so far for dev. Your test environment is also likely to use a different database. Just make sure you are connecting to the right one in the right situation - meaning setting your connection string / credentials as appropriate. Environment variables are the standard way to handle this.

Clone this wiki locally