Relational databases on AWS (AWS RDS + Aurora)
What is a relational database?
When we talk about relational databases, we're entering a world that's like a giant puzzle of information. Imagine you have a bunch of data that needs organizing, and later on, you want to be able to easily find each little piece of that data.
Now, to simplify this, think of an Excel spreadsheet. You've probably used one before, right? Well, a relational database is kind of like a supercharged version of that spreadsheet. Instead of just lists and columns, you have tables and rows. But the cool thing is that these tables can all be connected to each other, like pieces of a puzzle.
For example, let's say you're organizing what each user should have access to do in your system. You might have a table called 'Users' that lists all the users, and another table called 'Roles' that lists what users can do.
Now, here's the trick: each person listed in the 'Users' table can be connected to a specific role in the 'Roles' table:
So, when we talk about relational databases, we're talking about the art of connecting all this information smartly, so that everything makes sense and is easy to find when we need it. In short, that's the power of a relational database!
Now that we've got the basics down, let's dive a little deeper into two fantastic tools from AWS that can help us implement our relational databases in the cloud: AWS RDS and AWS Aurora.
AWS RDS (Relational Database Service)
What is RDS?
The Amazon RDS is a managed database service provided by AWS. It allows you to easily set up, operate, and scale relational databases in the cloud, without having to worry about the complexity of the infrastructure.
It allows us to create the following databases managed by AWS:
Example of a simple architecture using AWS RDS:
What are the advantages of using RDS?
Why should I use RDS instead of deploying my databases on an EC2?
RDS offers a range of advantages, from automated provisioning to disaster recovery. Let's explore how these features can benefit application development.
Automated Provisioning and OS Updates
AWS RDS automates tedious administrative tasks such as provisioning database instances and applying operating system patches. This frees up developers to focus on innovation and creating value for the business, rather than spending time on infrastructure maintenance.
Continuous Backups - Point in Time Restore (PITR)
With AWS RDS, backups are performed continuously and automatically, allowing the restoration of a database instance to any point within the retention window, usually up to the last second of activity. This Point-in-Time Restore (PITR) feature is crucial for quickly recovering data after human errors or system failures.
Monitoring Dashboards
AWS RDS provides integrated monitoring dashboards, such as RDS Performance Insights, which allow developers to quickly assess the workload on their databases and identify performance bottlenecks. This makes application optimization easier.
Read Replicas for Improved Read Performance
The main reason to use read replicas in RDS is to improve the performance and scalability of your database workloads. With read replicas, we have:
In the following example, I'm illustrating exactly how the read replica works, where we have instances A, B, and C only writing data to the RDS (but could also read), and instance D, which has an application generating reports and making many queries in our database, is pointing only to the read replica in AZ B:
Multi-AZ Configuration for Disaster Recovery
One of the coolest features of RDS is Multi-AZ, which helps us always maintain high availability and avoid risking letting our customers down!
In the diagram below, we have the example where our applications are pointing to the RDS in AZ A, and with Multi-AZ, the idea is to replicate the data to our RDS instance in AZ B, meaning that each change in one database will also be made in the other synchronously:
Recommended by LinkedIn
And for some reason, if our AZ A goes down, RDS will automatically detect it, perform the failover, and without requiring any manual intervention in our applications, the database DNS will be pointed to the instance in AZ B, as shown in the diagram below:
How is AWS RDS billed?
You pay only for what you use, with no minimum or setup fees, and the billing is based on:
Will I be charged for a stopped instance?
Oh, my friend, believe me, the bill doesn't stop when you shut down an Amazon RDS instance!
When you shut down an RDS instance, all those computing resources like CPU, memory, and storage stop working and are no longer reserved for you. But here's the catch: you'll still be charged for the storage that instance occupied, and there's more! You'll also have to pay for the automatic backups and database snapshots you've kept.
The cost of storage is calculated per gigabyte per month and varies depending on the type of storage you're using (SSD or HDD) and how much storage you've provisioned.
Oh, and don't forget about the backups! The automatic ones are like a daily record of your database, kept for a time you choose. The database snapshots, on the other hand, are like manually taken photos, you know?
So, even if the RDS instance is taking a nap, you still have to pay for the space it occupied and for the backups you made.
And lastly, but certainly not least... AWS Aurora?!
Amazon Aurora is a proprietary technology from AWS that represents a significant evolution in the realm of relational databases in the cloud. Designed to be fully compatible with MySQL and PostgreSQL, Aurora offers a host of performance and management improvements that make it an attractive choice for many organizations
Compatibility and Performance
Aurora supports both MySQL and PostgreSQL, allowing developers and businesses to migrate their existing applications to Aurora without the need to rewrite the code. But the real advantage of Aurora isn't just in compatibility, but also in performance. AWS has optimized Aurora for the cloud, claiming that it offers up to five times the performance of MySQL on RDS and over three times the performance of PostgreSQL on RDS.
Simplified Storage Management
With Aurora, concerns about storage management are significantly reduced. Aurora is designed to scale automatically in 10 GB increments, up to a maximum of 128 TB. This means that users don't need to provision excess storage space in advance, as Aurora grows as data needs increase.
Cost Efficiency
Although Aurora is more expensive than standard RDS options — costing about 20% more — it justifies this additional cost with its enhanced efficiency. For applications that require high performance and availability, Aurora can offer a better cost-benefit ratio due to its superiority in terms of performance and scalability.
When to use Aurora? When to use RDS?
Aurora
High Performance is Needed: If your application requires significantly better performance than traditional databases offer, Aurora might be the right choice. It offers up to five times the performance of MySQL and three times the performance of PostgreSQL on RDS, thanks to its optimization for AWS cloud.
Automatic Storage Scaling: With Aurora, you don't need to worry about storage provisioning. Aurora automatically adjusts storage in 10 GB increments, up to a maximum of 128 TB, which is ideal for applications with unpredictable data growth.
Availability and Durability: Aurora is designed to offer high availability by replicating data across three availability zones, ensuring availability of up to 99.99%. This is essential for critical applications where downtime is not an option.
Integration with Other AWS Services: Aurora offers zero-ETL integration with Amazon Redshift for near-real-time transactional data analytics, which can be a game-changer for analytical applications.
RDS
Cost is a Primary Consideration: If budget is a concern, other RDS options may be more suitable, as Aurora generally costs about 20% more than standard RDS options.
Compatibility with Multiple Database Engines: If you need flexibility to use different database engines like MariaDB, Oracle, or SQL Server, traditional RDS supports a wider variety of database engines.
Less Demanding Applications: For applications that don't require the high performance or high availability that Aurora offers, a standard RDS instance may be sufficient and more economical.
Conclusion
The AWS RDS represents a powerful solution that not only simplifies the administration of relational databases, but also offers advanced features to optimize performance, ensure availability, and scale applications efficiently. By leveraging these advantages, developers can focus on what they do best: creating innovative applications that drive business success.
Manoel, great post! AWS RDS and Aurora are indeed game-changers in the cloud database realm. Their flexibility and scalability have revolutionized data management for countless businesses. Thanks for sharing your insights!
Tech Lead | Software Engineer
9moJoão Vitor Gil da Silva