1 00:00:00,090 --> 00:00:00,940 ‫Going into the exam 2 00:00:00,940 --> 00:00:02,750 ‫is going to be extremely important 3 00:00:02,750 --> 00:00:05,200 ‫to understand the difference between RDS Read Replicas 4 00:00:05,200 --> 00:00:08,900 ‫and Multi AZ and understand exactly the use cases for those. 5 00:00:08,900 --> 00:00:10,650 ‫So this lecture is really dedicated 6 00:00:10,650 --> 00:00:12,710 ‫to understanding Read Replicas and Multi AZ. 7 00:00:12,710 --> 00:00:14,730 ‫So let's get started with the Read Replicas. 8 00:00:14,730 --> 00:00:16,840 ‫Read Replicas as the name indicates 9 00:00:16,840 --> 00:00:19,530 ‫help you to scale your reads. 10 00:00:19,530 --> 00:00:20,850 ‫So let's have an example. 11 00:00:20,850 --> 00:00:22,390 ‫Here, we have our application 12 00:00:22,390 --> 00:00:24,490 ‫and we have an RDS database instance 13 00:00:24,490 --> 00:00:27,310 ‫and our application performs reads and writes 14 00:00:27,310 --> 00:00:29,490 ‫to our database instance, 15 00:00:29,490 --> 00:00:31,130 ‫but say we want to scale the reads 16 00:00:31,130 --> 00:00:34,350 ‫because that's, main database instance can not scale enough. 17 00:00:34,350 --> 00:00:36,210 ‫It receives too many requests. 18 00:00:36,210 --> 00:00:39,490 ‫Well, we can create up to 15 Read Replicas 19 00:00:39,490 --> 00:00:42,240 ‫and they can be within the same availability zone, 20 00:00:42,240 --> 00:00:45,370 ‫cross availability zone, or cross region. 21 00:00:45,370 --> 00:00:46,770 ‫So three different options 22 00:00:46,770 --> 00:00:48,700 ‫and they're very important to remember. 23 00:00:48,700 --> 00:00:51,550 ‫So say we have another RDS instance Read Replica 24 00:00:51,550 --> 00:00:53,600 ‫and another one and what will happen 25 00:00:53,600 --> 00:00:56,340 ‫is that they will be an asynchronous replication 26 00:00:56,340 --> 00:00:58,850 ‫between the main RDS database instance 27 00:00:58,850 --> 00:01:01,000 ‫and the two Read Replicas. 28 00:01:01,000 --> 00:01:03,150 ‫Asynchronous, that means that the reads 29 00:01:03,150 --> 00:01:05,020 ‫are eventually consistent. 30 00:01:05,020 --> 00:01:06,040 ‫What that means is that, 31 00:01:06,040 --> 00:01:09,110 ‫for example, if your application reads from the Read Replica 32 00:01:09,110 --> 00:01:11,730 ‫before they had the chance to replicate the data 33 00:01:11,730 --> 00:01:13,470 ‫then you may get all data. 34 00:01:13,470 --> 00:01:14,570 ‫And this is why it's called 35 00:01:14,570 --> 00:01:18,560 ‫eventually consistent asynchronous replication. 36 00:01:18,560 --> 00:01:20,770 ‫And these replicas, they can be awesome 37 00:01:20,770 --> 00:01:23,130 ‫for reading for scaling reads 38 00:01:23,130 --> 00:01:26,750 ‫but they can also be promoted to their own database. 39 00:01:26,750 --> 00:01:28,320 ‫So you can take one of these replicas 40 00:01:28,320 --> 00:01:30,570 ‫and say, okay I want it to be its own database now 41 00:01:30,570 --> 00:01:31,450 ‫and take rights. 42 00:01:31,450 --> 00:01:33,350 ‫And so you promote it to its own database. 43 00:01:33,350 --> 00:01:36,750 ‫It's completely out of the replication mechanism after that 44 00:01:36,750 --> 00:01:40,090 ‫but it's lives and has its own life cycle afterwards. 45 00:01:40,090 --> 00:01:42,630 ‫So in case you wanna use Read Replicas, 46 00:01:42,630 --> 00:01:45,240 ‫the main application in orange in the top of the screen 47 00:01:45,240 --> 00:01:47,370 ‫must update the connection string 48 00:01:47,370 --> 00:01:49,880 ‫to leverage the list of all the Read Replicas 49 00:01:49,880 --> 00:01:51,513 ‫you have in your RDS cluster. 50 00:01:52,560 --> 00:01:53,713 ‫Okay, very nice. 51 00:01:54,630 --> 00:01:57,060 ‫So let's talk about a classic use case 52 00:01:57,060 --> 00:01:58,670 ‫for you to Read Replica. 53 00:01:58,670 --> 00:02:01,050 ‫So in this example, we have a production database 54 00:02:01,050 --> 00:02:02,625 ‫and it is taking on normal load. 55 00:02:02,625 --> 00:02:03,840 ‫So here we go. 56 00:02:03,840 --> 00:02:06,290 ‫Our production database is having read and writes 57 00:02:06,290 --> 00:02:08,590 ‫to our main RDS database instance. 58 00:02:08,590 --> 00:02:10,270 ‫And the new team comes in and say, 59 00:02:10,270 --> 00:02:12,080 ‫we want to run some reporting 60 00:02:12,080 --> 00:02:15,110 ‫and some analytics on top of your data. 61 00:02:15,110 --> 00:02:17,850 ‫And so if you plug in that reporting application 62 00:02:17,850 --> 00:02:20,130 ‫onto the main RDS database instance 63 00:02:20,130 --> 00:02:21,300 ‫then it's going to overload it 64 00:02:21,300 --> 00:02:24,270 ‫and possibly slow down the production application 65 00:02:24,270 --> 00:02:25,600 ‫and you don't want that. 66 00:02:25,600 --> 00:02:27,520 ‫So instead what you do as a solutions architect 67 00:02:27,520 --> 00:02:31,890 ‫is you create a Read Replica to run the new workload there. 68 00:02:31,890 --> 00:02:33,080 ‫So you create a Read Replica. 69 00:02:33,080 --> 00:02:34,940 ‫There is some asynchronous, a replication 70 00:02:34,940 --> 00:02:37,823 ‫that happens between your main RDS DB database instance 71 00:02:37,823 --> 00:02:38,900 ‫and your Read Replica 72 00:02:38,900 --> 00:02:41,990 ‫and then your reporting application can just do reads 73 00:02:41,990 --> 00:02:45,570 ‫from your Read Replica and run the analytics there. 74 00:02:45,570 --> 00:02:48,020 ‫The production application is completely unaffected 75 00:02:48,020 --> 00:02:50,290 ‫in this case and that's perfect. 76 00:02:50,290 --> 00:02:52,830 ‫So remember, if you have a Read Replica 77 00:02:52,830 --> 00:02:53,710 ‫you need to ensure 78 00:02:53,710 --> 00:02:56,720 ‫that it is only for SELECT type of statements 79 00:02:56,720 --> 00:02:58,890 ‫and SELECT is a SQL keyword. 80 00:02:58,890 --> 00:03:00,260 ‫SELECT means read. 81 00:03:00,260 --> 00:03:01,930 ‫And so you can not use keywords 82 00:03:01,930 --> 00:03:04,250 ‫such as INSERT, UPDATE or DELETE, 83 00:03:04,250 --> 00:03:06,080 ‫which change database itself. 84 00:03:06,080 --> 00:03:09,530 ‫Okay, Read Replicas is only for reads. 85 00:03:09,530 --> 00:03:11,250 ‫So, let's talk about the networking cost 86 00:03:11,250 --> 00:03:13,570 ‫associated with RDS Read Replica. 87 00:03:13,570 --> 00:03:17,660 ‫So in AWS, you should know that's normally there is a cost 88 00:03:17,660 --> 00:03:22,380 ‫when the data goes from one availability zone to another 89 00:03:22,380 --> 00:03:23,730 ‫but there are exceptions 90 00:03:23,730 --> 00:03:26,580 ‫and these exceptions are usually for managed services. 91 00:03:26,580 --> 00:03:29,270 ‫So for RDS Read Replica, this is a managed service. 92 00:03:29,270 --> 00:03:32,130 ‫If your Read Replica is within the same region, okay? 93 00:03:32,130 --> 00:03:35,610 ‫Different AZ, but same region, you're not paying that fee. 94 00:03:35,610 --> 00:03:39,060 ‫So what this means that if you have a RDS DB instance 95 00:03:39,060 --> 00:03:44,060 ‫in us-east-1a and then a Read Replica in us-east-1b, 96 00:03:44,250 --> 00:03:46,880 ‫and there is asynchronous replication 97 00:03:46,880 --> 00:03:48,660 ‫because this is a Read Replica, 98 00:03:48,660 --> 00:03:52,710 ‫even though the traffic goes from one AZ to a different AZ 99 00:03:52,710 --> 00:03:55,360 ‫that replication traffic is going to be free 100 00:03:55,360 --> 00:03:57,430 ‫because RDS is a managed service 101 00:03:57,430 --> 00:03:59,450 ‫and they give you that traffic for free. 102 00:03:59,450 --> 00:04:02,850 ‫But if you are using a cross region replica, 103 00:04:02,850 --> 00:04:05,370 ‫so you are in one region, us-east-1 104 00:04:05,370 --> 00:04:08,620 ‫and you go to another region, eu-west-1, for example 105 00:04:08,620 --> 00:04:11,900 ‫then your RDS DB instance and your Read Replica 106 00:04:11,900 --> 00:04:14,770 ‫will have replication that will go across regions 107 00:04:14,770 --> 00:04:18,903 ‫and this will incur a replication fee for your network. 108 00:04:20,120 --> 00:04:23,210 ‫Finally, let's talk about RDS Multi AZ 109 00:04:23,210 --> 00:04:26,470 ‫and Multi AZ is mainly used for Disaster Recovery. 110 00:04:26,470 --> 00:04:27,760 ‫So we have our application 111 00:04:27,760 --> 00:04:29,270 ‫and it performs the reads and writes 112 00:04:29,270 --> 00:04:30,840 ‫to our Master database instance 113 00:04:30,840 --> 00:04:32,720 ‫which is in availability zone A 114 00:04:32,720 --> 00:04:36,020 ‫and what we thinks you have is a synchronous replication 115 00:04:36,020 --> 00:04:38,990 ‫to a standby instance in AZ B, 116 00:04:38,990 --> 00:04:41,330 ‫and they will replicate every single change 117 00:04:41,330 --> 00:04:43,350 ‫in the Master synchronously. 118 00:04:43,350 --> 00:04:44,950 ‫So that means that when your application writes 119 00:04:44,950 --> 00:04:48,080 ‫to the Master, that change needs to also be replicated 120 00:04:48,080 --> 00:04:50,250 ‫to the standby to be accepted. 121 00:04:50,250 --> 00:04:53,580 ‫And so what we get out of it is one DNS name. 122 00:04:53,580 --> 00:04:56,220 ‫So your application talks to one DNS name 123 00:04:56,220 --> 00:04:58,700 ‫and in case there is a problem with the Master, 124 00:04:58,700 --> 00:05:01,920 ‫there will be an automatic failover to the standby database. 125 00:05:01,920 --> 00:05:04,340 ‫Thanks to that one DNS name. 126 00:05:04,340 --> 00:05:07,023 ‫So thanks to this, we increase the availability. 127 00:05:07,023 --> 00:05:10,670 ‫This is why it's called Multi AZ and they will be failover 128 00:05:10,670 --> 00:05:14,800 ‫in case we lose an entire AZ or we lose the network 129 00:05:14,800 --> 00:05:17,040 ‫or there is an instance or storage failure 130 00:05:17,040 --> 00:05:18,360 ‫for the Master database. 131 00:05:18,360 --> 00:05:20,550 ‫In which case, obviously the standby database 132 00:05:20,550 --> 00:05:22,420 ‫will become the new Master. 133 00:05:22,420 --> 00:05:25,010 ‫He don't need to do any manual intervention in your apps 134 00:05:25,010 --> 00:05:26,770 ‫as long as it tries to keep on connecting 135 00:05:26,770 --> 00:05:28,560 ‫to your database automatically at some point, 136 00:05:28,560 --> 00:05:30,380 ‫it will fail over to the standby 137 00:05:30,380 --> 00:05:33,750 ‫that will be promoted as the Master, and you'll be good 138 00:05:33,750 --> 00:05:34,980 ‫and it's not used for scaling. 139 00:05:34,980 --> 00:05:36,110 ‫So as you can see here, 140 00:05:36,110 --> 00:05:38,800 ‫the standby database is just for standby. 141 00:05:38,800 --> 00:05:40,050 ‫No one can read to it. 142 00:05:40,050 --> 00:05:44,170 ‫No one can write to it, it's just here as a failover 143 00:05:44,170 --> 00:05:47,130 ‫in case anything goes on with your Master database. 144 00:05:47,130 --> 00:05:50,120 ‫So, quick question is, is there a possibility 145 00:05:50,120 --> 00:05:53,200 ‫to have the Read Replicas being set up as Multi AZ 146 00:05:53,200 --> 00:05:54,200 ‫for Disaster Recovery? 147 00:05:54,200 --> 00:05:57,600 ‫And the answer is yes, you can set up your Read Replica 148 00:05:57,600 --> 00:05:59,830 ‫as a Multi AZ if you want it to. 149 00:05:59,830 --> 00:06:02,430 ‫And that is a common exam question, okay? 150 00:06:02,430 --> 00:06:04,500 ‫So that's it for the difference between Read Replicates 151 00:06:04,500 --> 00:06:07,180 ‫and Multi AZ, but you need to absolutely understand this 152 00:06:07,180 --> 00:06:08,013 ‫going into the exam 153 00:06:08,013 --> 00:06:11,090 ‫because a lot of questions will go and be about it. 154 00:06:11,090 --> 00:06:13,420 ‫So a question that can come up in the exam 155 00:06:13,420 --> 00:06:15,980 ‫is around how do we make an RDS database 156 00:06:15,980 --> 00:06:19,370 ‫go from Single AZ to Multi AZ? 157 00:06:19,370 --> 00:06:20,490 ‫So what you should know 158 00:06:20,490 --> 00:06:23,160 ‫is that it is a zero downtime operation. 159 00:06:23,160 --> 00:06:25,410 ‫That means you do not need to stop the database 160 00:06:25,410 --> 00:06:28,430 ‫to go from Single AZ to Multi AZ. 161 00:06:28,430 --> 00:06:29,470 ‫The only thing you need to do 162 00:06:29,470 --> 00:06:31,780 ‫is to click on modify for the database 163 00:06:31,780 --> 00:06:33,930 ‫and enable Multi AZ. 164 00:06:33,930 --> 00:06:35,630 ‫That means that your RDS database instance 165 00:06:35,630 --> 00:06:37,350 ‫is going to go to have a Master, 166 00:06:37,350 --> 00:06:40,530 ‫to have a standby DB with synchronous replication 167 00:06:40,530 --> 00:06:44,020 ‫without you doing anything except modifying that setting 168 00:06:44,020 --> 00:06:45,730 ‫and the database will not stop. 169 00:06:45,730 --> 00:06:47,070 ‫Now, this is what the exam will ask you 170 00:06:47,070 --> 00:06:49,740 ‫but I wanna show you what will happen behind the scenes 171 00:06:49,740 --> 00:06:50,910 ‫for it to work. 172 00:06:50,910 --> 00:06:53,820 ‫So, the following will happen internally. 173 00:06:53,820 --> 00:06:57,290 ‫There will be a snapshot taken by RDS automatically 174 00:06:57,290 --> 00:06:58,700 ‫of your main database 175 00:06:58,700 --> 00:07:01,180 ‫and that this snapshot will be restored 176 00:07:01,180 --> 00:07:04,270 ‫into a new standby database, okay? 177 00:07:04,270 --> 00:07:06,940 ‫And then once the standby database is restored, 178 00:07:06,940 --> 00:07:08,900 ‫there will be synchronization established 179 00:07:08,900 --> 00:07:10,360 ‫between the two database 180 00:07:10,360 --> 00:07:11,990 ‫and so therefore the standby database 181 00:07:11,990 --> 00:07:15,570 ‫will catch up to the main RDS database and there you go, 182 00:07:15,570 --> 00:07:17,920 ‫you will be in a Multi AZ setup. 183 00:07:17,920 --> 00:07:19,380 ‫So that's it for this lecture. 184 00:07:19,380 --> 00:07:20,213 ‫I hope you liked it, 185 00:07:20,213 --> 00:07:22,040 ‫and I will see you in the next lecture.