Distributed Managed PostgreSQL Database Alternatives in the Cloud
Tags: aws, database, postgres, architecture
Published: 2023-04-03 15:38:54

In 2020 I have published a blog post called [Running MySQL Managed Database in the Cloud](https://eyal-estrin.medium.com/running-mysql-managed-database-in-the-cloud-62b9a282ec3c), comparing different alternatives for running MySQL database in the cloud.  
In this blog post, I will take one step further, comparing PostgreSQL database alternatives deployed on a distributed system.  
## Background
[PostgreSQL](https://www.postgresql.org/) is an open-source relational database, used by many companies, and is very common among cloud applications, where companies prefer an open-source solution, supported by a strong community, as an alternative to commercial database engines.  
The simplest way to run the PostgreSQL engine in the cloud is to choose one of the managed database services, such as [Amazon RDS for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) or [Google Cloud SQL for PostgreSQL](https://cloud.google.com/sql/docs/postgres), and allow you to receive a fully managed database.  
In this scenario, you as the customer, receive a fully managed PostgreSQL database cluster, that spans across multiple availability zones, and the cloud provider is responsible for maintaining the underlining operating system, including patching, hardening, monitoring, and backup (up to the service limits).  
As a customer, you receive an endpoint (i.e., DNS name and port), configure access controls (such as AWS Security groups or GCP VCP Firewall rules), and set authentication and authorization for what identities have access to the managed database.  
This solution is suitable for most common use cases if your applications (and perhaps customers) are in a specific region.  
What happens in a scenario where you would like to design a truly highly available architecture span across multiple regions (in the rare case of an outage in a specific region) and serve customers across the globe, deploying your application close to your customers?  
The solution for allowing high availability and multi-region deployment is to deploy the PostgreSQL engine in a managed distributed database.  
## PostgreSQL Distributed Database Alternatives
The distributed system allows you to run a database across multiple regions while keeping the data synchronized.  
In a distributed database, the compute layer (i.e., virtual machines) running the database engine is deployed on separate nodes from the storage and logging layer, allowing you to gain the benefits of the cloud provider's backend infrastructure low-latency replication capabilities.  
In each system, there is a primary cluster (which oversees read/write actions) and one or more secondary clusters (read-only replicas).  
Architecture diagram:  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytg48j460nhgpm9dpid1.png)

Let us examine some of the cloud providers' alternatives:  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/43lmx9w2n6g96mz97zk8.JPG)

### Additional Reference
* [Working with Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)  

## Summary
In this blog post, I have compared two alternatives for running PostgreSQL-compatible database in a distributed architecture.  
If you are looking for a relational database solution with high durability that will auto-scale according to application load, and with the capability to replicate data across multiple regions, you should consider one of the alternatives I have mentioned in this blog post.  
As always, I recommend you to continue reading and expanding your knowledge on the topic and evaluate during the architecture design phase, if your workloads can benefit from a distributed database system.  

### Additional Reference
* [Amazon Aurora: Design considerations for high throughput cloud-native relational databases](https://assets.amazon.science/dc/2b/4ef2b89649f9a393d37d3e042f4e/amazon-aurora-design-considerations-for-high-throughput-cloud-native-relational-databases.pdf)  

### About the Author
Eyal Estrin is a cloud and information security architect, the owner of the blog [Security & Cloud 24/7](https://security-24-7.com/) and the author of the book [Cloud Security Handbook](https://amzn.to/3xMI4Ak), with more than 20 years in the IT industry.  
Eyal is an [AWS Community Builder](https://aws.amazon.com/developer/community/community-builders/) since 2020.  
You can connect with him on [Twitter](https://twitter.com/eyalestrin) and [LinkedIn](https://www.linkedin.com/in/eyalestrin/).