{"id":2839,"date":"2019-06-20T13:47:41","date_gmt":"2019-06-20T11:47:41","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=2839"},"modified":"2019-08-31T00:32:06","modified_gmt":"2019-08-30T22:32:06","slug":"relational-database-service-rds","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2019\/06\/20\/relational-database-service-rds\/","title":{"rendered":"Relational Database Service (RDS)"},"content":{"rendered":"<p>RDS is a Database as a Service (DBaaS) product. It can be used to provision a fully functional database without the admin overhead traditionally associated with DB platforms. It can perform at scale, be made publicly accessible, and can be configured for demanding availability and durability scenarios.<\/p>\n<p><!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2840 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/RDS1.jpg\" alt=\"\" width=\"627\" height=\"641\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/RDS1.jpg 627w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/RDS1-293x300.jpg 293w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/p>\n<p>RDS supports a number of database engines:<\/p>\n<ul>\n<li>MySQL, MariaDB, PostgreSQL, Oracle, Microsoft SQL Server<\/li>\n<li>Aurora: An in-house developed engine with substantial feature and performance enhancements<\/li>\n<\/ul>\n<p>RDS can be deployed in single AZ or Multi-AZ mode (for resilience) and supports the following instance types:<\/p>\n<ul>\n<li>General purpose (currently DB.M4 and DB.M5)<\/li>\n<li>Memory optimized (currently DB.R4 and DB.R5, and DB.X1 e and DB.X1 for Oracle)<\/li>\n<li>Burstable (DB.T2 and DB.T3)<\/li>\n<\/ul>\n<p>Two types of storage are supported:<\/p>\n<ul>\n<li>General Purpose SSD (gp2): 3 IOPS per GIB, burst to 3,000 IOPS (pool architecture like EBS)<\/li>\n<li>Provisioned IOPS SSD (io1): 1,000 to 80,000 IOPS (engine dependent) size, and IOPS can be configured independently<\/li>\n<\/ul>\n<p>RDS instances are charged based on:<\/p>\n<ul>\n<li>Instance size<\/li>\n<li>Provisioned storage (not used)<\/li>\n<li>IOPS if using io1<\/li>\n<li>Data transferred out<\/li>\n<li>Any backups\/snapshots beyond the 100% that is free with each DB instance<\/li>\n<\/ul>\n<p>RDS supports encryption with the following limits\/restrictions\/conditions:<\/p>\n<ul>\n<li>Encryption can be configured when creating DB instances.<\/li>\n<li>Encryption can be added by taking a snapshot, making an encrypted snapshot, and creating a new encrypted instance from that encrypted snapshot.<\/li>\n<li>Encryption cannot be removed.<\/li>\n<li>Read Replicas need to be the same state as the primary instance (encrypted or not).<\/li>\n<li>Encrypted snapshots can be copied between regions \u2014 but a new destination region KMS CMK is used (because they are region specific).<\/li>\n<\/ul>\n<p>Network access to an RDS instance is controlled by a security group (SG) associated with the RDS instance.<\/p>\n<p>&nbsp;<\/p>\n<p>RDS is capable of a number of different types of backups. Automated backups to S3 occur <strong>daily<\/strong> and can be retained from<strong> 0<\/strong> to <strong>35 days<\/strong> (with <strong>0<\/strong> being <strong>disabled<\/strong>). Manual snapshots are taken manually and exist until deleted, and point-in-time log-based backups are also stored on S3.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2844 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/RDS2.jpg\" alt=\"\" width=\"607\" height=\"575\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/RDS2.jpg 607w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/RDS2-300x284.jpg 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Multi-AZ<\/span><\/p>\n<ul>\n<li>RDS can be provisioned in single or Multi-AZ mode.<\/li>\n<li>Multi-AZ provisions a primary instance and a standby instance in a different AA of the same region.<\/li>\n<li><strong>Only<\/strong> the <strong>primary<\/strong> can be accessed using the instance <strong>CNAME<\/strong>.<\/li>\n<li>There is no performance benefit, but it provides a better RTO than restoring a snapshot.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2846 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/MultiAZ.jpg\" alt=\"\" width=\"598\" height=\"433\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/MultiAZ.jpg 598w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/MultiAZ-300x217.jpg 300w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><\/p>\n<p>Replication of data is <strong>synchronous<\/strong> \u2014 it&#8217;s copied in real time from the <strong>primary<\/strong> to the <strong>standby<\/strong> as it&#8217;s written. The primary and master each have their own storage. <strong>Backups<\/strong> are taken using the <strong>standby<\/strong>, ensuring no performance impact. <strong>Maintenance<\/strong> is performed on the <strong>standby<\/strong> first, which is then promoted to minimize downtime.<\/p>\n<p>&nbsp;<\/p>\n<p>Multi-AZ<\/p>\n<ul>\n<li>Provisions and maintains a standby replica in a different AZ<\/li>\n<li>The primary synchronously replicates to the standby instance for redundancy<\/li>\n<li>Can reduce downtime in the event of a failure on the primary<\/li>\n<li>The feature can be turned on from the console or API<\/li>\n<li>Amazon automatically handles replication<\/li>\n<li>Replication can cause higher write latency: Using Provisioned IOPS is recommended<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2851 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/MultiAZ2.jpg\" alt=\"\" width=\"543\" height=\"321\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/MultiAZ2.jpg 543w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/MultiAZ2-300x177.jpg 300w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/p>\n<p><span style=\"color: #999999;\">Maintenance<\/span><\/p>\n<p>AWS will perform the following steps:<\/p>\n<ul>\n<li>Perform maintenance on the standby<\/li>\n<li>Promote the standby<\/li>\n<li>Perform maintenance on the old primary, now the standby<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Read Replicas<\/span> are <strong>read-only<\/strong> copies of an RDS instance that can be created in the same region or a different region from the primary instance.<\/p>\n<p>Read Replicas can be addressed <strong>independently<\/strong> (each having their <strong>own DNS name)<\/strong> and used for read workloads, allowing you to scale reads. <strong>Five Read<\/strong> Replicas can be created from a RDS instance, allowing a <strong>5x<\/strong> increase in reads. Read Replicas can be created from Read Replicas, and they can be promoted to primary instances and can be themselves Multi-AZ.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2847 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ReadReplicas.jpg\" alt=\"\" width=\"638\" height=\"503\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ReadReplicas.jpg 638w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ReadReplicas-300x237.jpg 300w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/p>\n<p>Reads from a Read Replica are eventually consistent \u2014 normally seconds, but the application needs to support it.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Scaling for Performance<\/span><\/p>\n<ul>\n<li>Read replicas can be used to offload work from the main database:\n<ul>\n<li>Writes go to the source instance.<\/li>\n<li>Reads go to the read replica(s).<\/li>\n<\/ul>\n<\/li>\n<li>Replication to Read Replicas is made asynchronously (not at the same time) .<\/li>\n<li>Data is written to the source instance and then replicated to the read replica(s).<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2864 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ReadReplica.jpg\" alt=\"\" width=\"522\" height=\"236\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ReadReplica.jpg 522w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ReadReplica-300x136.jpg 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><em>Scenario<\/em>: You need to pull data for analysis, but you don&#8217;t want to degrade performance on your production database.<\/p>\n<p><em>Solution<\/em>: Create a read replica that&#8217;s only used for this reason.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">AWS RDS Read Replication vs. Multi-AZ Failover Deployments<\/span><\/p>\n<ul>\n<li>Read replicas are built primarily for <strong>performance<\/strong> and <strong>offloading work<\/strong>.<\/li>\n<li>Multi-AZ deployments are used for <strong>high availability<\/strong> and<strong> durability<\/strong>.<\/li>\n<li>Multi-AZ deployments give us <strong>synchronous<\/strong> replication instead of <strong>asynchronous<\/strong>.<\/li>\n<li>Multi-AZ deployments are only used to perform a<strong> failover<\/strong>; they are <strong>idle<\/strong> the rest of the time.<\/li>\n<li>Read replicas are used to serve legitimate traffic.<\/li>\n<li>It is often beneficial to use <strong>both<\/strong> of these as complements.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">What Can Trigger a Failover?<\/span><\/p>\n<ul>\n<li>Loss of availability in the primary Availability Zone<\/li>\n<li>Loss of network connectivity to the primary instance<\/li>\n<li>Resource failure with the underlying virtualized resources<\/li>\n<li>Storage failure on the primary database<\/li>\n<li>The DB instance&#8217;s server type is changed<\/li>\n<li>Maintenance<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2853 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/FailOver.jpg\" alt=\"\" width=\"551\" height=\"312\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/FailOver.jpg 551w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/FailOver-300x170.jpg 300w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">How Do Failovers Work?<\/span><\/p>\n<ul>\n<li>The process is automated by AWS:<\/li>\n<\/ul>\n<p>1. Amazon detects an issue and starts the failover process.<\/p>\n<p>2. DNS records are modified to point to the standby instance.<\/p>\n<p>3. The application re-establishes any existing DB connections.<\/p>\n<ul>\n<li>The application requires no changes since the DB endpoint is the same.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">How Do We Know When a Failover Happens?<\/span><\/p>\n<ul>\n<li>Use RDS events to notify via email or SMS.<\/li>\n<li>Use the API or console to manually check events.<\/li>\n<li>Use the API or console to check the state of the Multi-AZ deployment.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Monitoring for performance and availability<br \/>\n<\/span><\/p>\n<ul>\n<li>Managed database web service AWS manages patching, backups, detecting failures, and recovery<\/li>\n<li>Supports these engines: MySQL, MariaDB, PostgreSQL, Oracle, Microsoft SQL Server, and Amazon Aurora<\/li>\n<\/ul>\n<p>Instance Classes<\/p>\n<ul>\n<li>General Purpose (M4, M5)<\/li>\n<li>Memory Optimized (R4, R5, X1e, X1)<\/li>\n<li>Burstable Performance (T2, T3)<\/li>\n<\/ul>\n<p>Storage Type<\/p>\n<ul>\n<li>General Purpose (SSD) 3 IOPS per GIB, burst to 3,000 IOPS<\/li>\n<li>Provisioned IOPS (SSD) \u2022 1,000 to 80,000 IOPS (depending on the engine)<\/li>\n<\/ul>\n<p>Monitoring<\/p>\n<ul>\n<li>CloudWatch metrics:\n<ul>\n<li>Swap Usage: Increase = low or no available RAM<\/li>\n<li>ReadIOPS\/WriteIOPS: Use this to determine storage type changes<\/li>\n<li>ReadLatency\/VVriteLatency: Higher latency = more IOPS needed<\/li>\n<li>ReadThroughPut\/WriteThroughput: Average bytes per second<\/li>\n<\/ul>\n<\/li>\n<li>RDS events:\n<ul>\n<li>A record of instance, snapshot, security group, and parameter group events<\/li>\n<\/ul>\n<\/li>\n<li>Enhanced monitoring:\n<ul>\n<li>Real-time metrics for the OS of the DB instance<\/li>\n<li>Gets metrics from an agent on the instance<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RDS is a Database as a Service (DBaaS) product. It can be used to provision a fully functional database without the admin overhead traditionally associated with DB platforms. It can perform at scale, be made publicly accessible, and can be configured for demanding availability and durability scenarios.<\/p>\n","protected":false},"author":1,"featured_media":2841,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2839"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=2839"}],"version-history":[{"count":13,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2839\/revisions"}],"predecessor-version":[{"id":2865,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2839\/revisions\/2865"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media\/2841"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=2839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=2839"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=2839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}