Featured Image
Software Development

Comparing RDS vs EC2 for PostgreSQL DB

Unless you are new to Backend development, it is likely that you have heard about Amazon RDS. In brief, Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the cloud. It provides cost-efficient, resizable capacity for an industry-standard relational database and manages common database administration tasks.

Amazon RDS PostgreSQL

Amazon RDS PostgreSQL

I will try to compare Amazon RDS vs Amazon EC2 for PostgreSQL database. This post might help you in choosing either use Amazon RDS or your own Amazon EC2 instance with PostgreSQL installed.

One of the advantages of developers using Amazon RDS instead of managing their own databases is that it reduces or eliminates their administrative responsibilities.

Benefits of using Amazon RDS

Benefits of using Amazon RDS over Amazon EC2 for PostgreSQL server.

Setup

Setting up a PostgreSQL database on Amazon RDS is just a few clicks and go. There is no need to buy hardware, install the software and manage database access. You can configure everything from the AWS Dashboard and its done!

Availability

Amazon RDS is a highly available relational database. It comes with a feature called Amazon RDS Multi-AZ Deployment, which automatically creates a primary DB Instance and synchronously replicates the data to a standby instance in a different Availability Zone (AZ).

If you go with your own EC2 instance, you have to setup PostgreSQL for high availability from one of the different replication solutions.

Backups

With Amazon RDS, you get automated backups that let you recover to a pointed time you choose. You also get a simple way to take consistent and deliverable snapshots on-demand and keep them as long as you want.

While setting up backup & restore on PostgreSQL is not as easy as it is with Amazon RDS.

Disaster Recovery

With the Multi-AZ feature, AWS provides a synchronous “standby” replica of every database in another “zone.” Since both the database and its replica are in sync, there is no chance of data loss. It also offers domain name server (DNS) to access RDS, so even if the master database instance goes down, an RDS automatic failover mechanism will change the master DNS to a replica in order to achieve high availability.

While PostgreSQL directly does not provide automatic failover, you will have to manually setup automatic failover with PostgreSQL. You might also have to configure repmgr to manage replication and failover in a cluster of PostgreSQL servers.

Scalability

Scaling up your database becomes very easy with Amazon RDS. You can scale your database by adding replicas. You can scale your RDS Instance vertically and horizontally with single push of a button.

You might need to setup Streaming Replication to scale your database. You will also face a downtime.

Performance

AWS RDS offers PIOPS (Provisioned IOPS) in order to achieve fast, consistent and predictable Input/Output (I/O) performance.

Monitoring

Amazon RDS sends metrics to CloudWatch every single minute for each and every database instance that is active with no additional charge.

Security

Amazon RDS allow you to secure your data with the help of data encryption. You can encrypt it with the keys and it is managed by AWS Key Management Service. You can read more about Encrypting Amazon RDS Resources.

Software Patching

Amazon RDS makes sure that your database stays up-to-date with latest patches.

Limitations of Using Amazon RDS

Let us discuss about some of the cons of using AWS RDS.

  • No access to the RDS instance. Yes, you heard it right, as RDS is a managed database. you can’t access the server operating system.
  • Server time is fixed to UTC.

Not much limitations using Amazon RDS right? Let’s compare pricing, considering similar instance configurations.

Price Comparison

EC2 Pricing

Instance type: m4.large | 2 vCPUs | 8 GB Memory | Moderate I/O

Storage: EBS General Purpose SSD | 100 GB @ $0.1 per GB per month

Total Cost (approximate): $85 per month

RDS Pricing

Instance type: db.m4.large | 2 vCPUs | 8 GB Memory | Moderate I/O

Storage: 100 GB

Total Cost (approximate): $155 per month

RDS clearly sounds expensive, but it has its own advantages. There is no right or wrong decision when choosing RDS or EC2 for database. And like most of the things, it’s a cost vs effort/complexity trade-off.

If you’re considering deploying your app on EC2, take a look at this guide for deploying your React app on AWS EC2 for global accessibility.

Choosing Between RDS and EC2

If you’re looking for a simple, low-maintenance solution, RDS should be a better option. When it comes to production deployments, the multi-AZ deployment provided by RDS turns out to be very useful, definitely reducing efforts/cost for the database/devops engineer. If you have to do complex configurations like optimizing postgres config file, migrate Write-Ahead-Log, run pgbouncer etc., having your database on EC2 is the only option.

Thanks for reading this article. Please recommend this article if you found it helpful.

Also read: Evaluating App Performance: Native Android versus Flutter Development

author
Kartikeya Rokde
Python/Django Lead Developer - Responsible for designing and architect scalable cloud infrastructure and develop service architecture for several projects/products. - Leading development and managing several projects. Tech lead. - Responsible for implementation of best practices and development standards. - Working with customers to provide solutions spanning across a wide range of technologies.