[SEO Subhead]
This Guidance demonstrates how to configure active-active replication with up to nine Amazon Relational Database Service (Amazon RDS) for MySQL instances using the Group Replication plugin. With the provided AWS CloudFormation stacks and scripts, you can implement a multi-primary mode topology to achieve continuous availability for your applications. Write operations are distributed across multiple database instances in an active-active cluster, maximizing availability and reducing write latency.
Please note: [Disclaimer]
Architecture Diagram
[Architecture diagram description]
Step 1
An existing Amazon Relational Database Service (Amazon RDS) for MySQL instance is required to deploy this Guidance. The source application runs on Amazon Elastic Compute Cloud (Amazon EC2), Amazon Elastic Kubernetes Service (Amazon EKS), Amazon Elastic Container Service (Amazon ECS), or an environment of your choice.
In this Guidance, we assume the application is deployed through Amazon EC2 instances across multiple Availability Zones (AZs). The Amazon RDS for MySQL instance can be encrypted using the default Amazon Key Management Service (AWS KMS) or a customer managed key.
Step 2
Once the prerequisites are complete, the AWS CloudFormation stacks will create resources such as RDS for MySQL instances, ProxySQL, and a Network Load Balancer. Additionally, an Amazon Simple Notification Service (Amazon SNS) topic, an AWS Lambda function, and Amazon EventBridge rules will be deployed.
- 2a: Network Load Balancer automatically distributes your incoming traffic from your applications across multiple targets, such as ProxySQL on Amazon EC2 instances, in one or more AZs.
- 2b: ProxySQL redirects the traffic to the active DB instance of the Group Replication cluster.
Step 3
An Amazon CloudWatch alarm is created to monitor RDS failure events (such as DB instance shutdown, restart, failover, or failure) and notify through an Amazon SNS topic.
Step 4
An EventBridge rule is configured to monitor for RDS failure events (such as DB instance shutdown, restart, or failure) and sends notifications through an Amazon SNS topic. The rule also calls a Lambda function when the event occurs.
Step 5
A Lambda function provides a framework to add any additional functionalities during the RDS failure event. Some of the functionalities that can be added, but are not limited to, are:
- If one of the instances in a Group Replication topology is restarted, verify that the restarted DB instance is joined back to the Group Replication topology.
- If one of the instances in a Group Replication topology is upgraded, the DB instance will be in read_only mode. In this case, upgrade the other DB instances in the replication topology.
- Perform periodic health checks using MySQL performance schema tables, and if one DB instance is in a suspended state, redirect the traffic to other DB instances in the Group Replication topology.
Get Started
Deploy this Guidance
Well-Architected Pillars
The AWS Well-Architected Framework helps you understand the pros and cons of the decisions you make when building systems in the cloud. The six pillars of the Framework allow you to learn architectural best practices for designing and operating reliable, secure, efficient, cost-effective, and sustainable systems. Using the AWS Well-Architected Tool, available at no charge in the AWS Management Console, you can review your workloads against these best practices by answering a set of questions for each pillar.
The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible.
-
Operational Excellence
RDS for MySQL, EventBridge, Amazon SNS, and AWS CloudTrail help you with tracking and reviewing logs and information for quick error review and incident responses. Specifically, RDS for MySQL allows you to set up multi-primary mode between your RDS for MySQL database instances to provide continuous availability for your applications.
-
Security
Elastic Load Balancing (ELB) automatically distributes your incoming traffic across multiple targets; it monitors the health of its registered targets and routes traffic only to the healthy targets. AWS KMS is used in this Guidance to provide default encryption with the option to use custom KMS keys. The encrypted DB instances for RDS for MySQL offer an additional layer of data protection by encrypting underlying storage, backups, replicas, and snapshots. Lastly, consider protecting your resources with identity-based policies such as AWS Identity and Access Management (IAM).
-
Reliability
RDS for MySQL offers high availability through data replication across multiple AZs, and the Group Replication plugin offers data resilience. For durable storage for RDS snapshots, use Amazon Simple Storage Service (Amazon S3) to secure storage for critical data.
ELB automatically distributes your incoming traffic across multiple targets, such as Amazon EC2 instances, containers, and IP addresses in one or more AZs. It monitors the health of its registered targets and routes traffic only to the healthy targets, which improves application availability. ELB scales your load balancer as your incoming traffic changes over time.
Lastly, CloudFormation automates resource deployment and provisions a rollback upon failures, supporting reliability in the midst of failures.
-
Performance Efficiency
Use the Group Replication plugin in RDS for MySQL, along with configurations like Transaction Size and Follow Controls, to optimize your application's performance and replication throughput. Also, using ProxySQL to split read and write operations across the RDS DB instances further enhances your application's performance. Moreover, Lambda and EventBridge are scalable, customizable services that help you maintain the active-active cluster topology.
-
Cost Optimization
RDS for MySQL allows you to deploy scalable MySQL servers with cost-efficient and resizable hardware capacity. And with ELB, you pay only for what you use. Finally, the broad and deep portfolio of Amazon EC2 instances, combined with Amazon EC2 Auto Scaling, helps you tailor compute resources to your business needs and scale capacity up and down based on observed demand.
-
Sustainability
The auto scaling capabilities of Amazon EC2 help align resources with application needs, minimizing waste and promoting sustainability. We recommend Graviton-based Amazon EC2 instances for RDS for MySQL to reduce your carbon footprint by using up to 60% less energy for the same performance as comparable x86-based instances. Additionally, the ability to stop and start RDS for MySQL DB instances eliminates the need for running resources for temporary testing or daily development activities.
Related Content
Introducing Group Replication plugin for active/active replication on Amazon RDS for MySQL
Disclaimer
The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.
References to third-party services or organizations in this Guidance do not imply an endorsement, sponsorship, or affiliation between Amazon or AWS and the third party. Guidance from AWS is a technical starting point, and you can customize your integration with third-party services when you deploy the architecture.