1 00:00:00,190 --> 00:00:01,130 ‫So let's first talk 2 00:00:01,130 --> 00:00:02,130 ‫about the first service 3 00:00:02,130 --> 00:00:04,500 ‫which would allow us to decouple our applications, 4 00:00:04,500 --> 00:00:06,320 ‫which is Amazon SQS, 5 00:00:06,320 --> 00:00:08,410 ‫which stands for Simple Queue Service. 6 00:00:08,410 --> 00:00:09,540 ‫So what's a queue? 7 00:00:09,540 --> 00:00:12,910 ‫Well, say we are creating an SQS queue, right here. 8 00:00:12,910 --> 00:00:14,540 ‫What we enable us to do is 9 00:00:14,540 --> 00:00:18,550 ‫to have producers send messages into that queue. 10 00:00:18,550 --> 00:00:20,330 ‫And then, it could be one producer, 11 00:00:20,330 --> 00:00:23,360 ‫but it could be as well multiple producers. 12 00:00:23,360 --> 00:00:26,470 ‫And then, once the messages are stored in a queue, 13 00:00:26,470 --> 00:00:28,740 ‫then they can be read by consumers 14 00:00:28,740 --> 00:00:29,990 ‫who will be polling the queue, 15 00:00:29,990 --> 00:00:32,030 ‫that means requesting messages from the queue, 16 00:00:32,030 --> 00:00:33,160 ‫they will be polling the queue, 17 00:00:33,160 --> 00:00:34,520 ‫and it could be one consumer, 18 00:00:34,520 --> 00:00:36,830 ‫but it could also be multiple consumers. 19 00:00:36,830 --> 00:00:38,120 ‫And in this example, 20 00:00:38,120 --> 00:00:40,270 ‫once the consumer polls messages, 21 00:00:40,270 --> 00:00:42,160 ‫they will share the work so each consumer 22 00:00:42,160 --> 00:00:43,590 ‫will get different messages, 23 00:00:43,590 --> 00:00:45,950 ‫and when they're done processing a message, 24 00:00:45,950 --> 00:00:48,590 ‫maybe for example, to process a video, 25 00:00:48,590 --> 00:00:50,210 ‫then they will delete the message 26 00:00:50,210 --> 00:00:52,270 ‫from the queue and it will be gone. 27 00:00:52,270 --> 00:00:53,920 ‫So in this mechanism, 28 00:00:53,920 --> 00:00:56,140 ‫we have the producer sending messages into the queue, 29 00:00:56,140 --> 00:00:57,810 ‫and they're decoupled from the consumer 30 00:00:57,810 --> 00:00:59,210 ‫reading the messages from the queue, 31 00:00:59,210 --> 00:01:01,930 ‫and processing them at different speed. 32 00:01:01,930 --> 00:01:03,700 ‫So when you have SQS, 33 00:01:03,700 --> 00:01:07,260 ‫turns out that it is the AWS oldest offering, 34 00:01:07,260 --> 00:01:08,480 ‫it's over ten years old, 35 00:01:08,480 --> 00:01:10,490 ‫it was one of the first services 36 00:01:10,490 --> 00:01:13,870 ‫to appear as part of the AWS cloud. 37 00:01:13,870 --> 00:01:16,090 ‫It is fully managed, so it's a serverless service, 38 00:01:16,090 --> 00:01:17,420 ‫you don't provision servers, 39 00:01:17,420 --> 00:01:20,090 ‫and it's used to decouple applications. 40 00:01:20,090 --> 00:01:21,600 ‫So this is the exam tip, 41 00:01:21,600 --> 00:01:23,940 ‫if you see "decouple", then think of SQS. 42 00:01:23,940 --> 00:01:26,150 ‫It will scale seamlessly, from example, 43 00:01:26,150 --> 00:01:27,610 ‫from one message a second, 44 00:01:27,610 --> 00:01:29,950 ‫to tens of thousands of messages per second. 45 00:01:29,950 --> 00:01:32,070 ‫And the default retention of the messages 46 00:01:32,070 --> 00:01:34,940 ‫is four days, maximum of 14 days. 47 00:01:34,940 --> 00:01:35,960 ‫So you need to process them 48 00:01:35,960 --> 00:01:38,010 ‫within that default retention. 49 00:01:38,010 --> 00:01:40,720 ‫There's no limit to how many messages can be in a queue. 50 00:01:40,720 --> 00:01:43,530 ‫And then, once the consumers read the messages, 51 00:01:43,530 --> 00:01:46,110 ‫then they have to be deleted, so they're gone. 52 00:01:46,110 --> 00:01:47,760 ‫There is low latency, we're talking about less 53 00:01:47,760 --> 00:01:50,470 ‫than ten milliseconds on publish and subscribe. 54 00:01:50,470 --> 00:01:52,210 ‫And then, consumers share the work 55 00:01:52,210 --> 00:01:54,683 ‫to read messages and scale horizontally. 56 00:01:55,830 --> 00:01:58,110 ‫So SQS can be used to decouple 57 00:01:58,110 --> 00:01:59,490 ‫between your application tiers. 58 00:01:59,490 --> 00:02:02,180 ‫So here's a classic solution architecture. 59 00:02:02,180 --> 00:02:03,250 ‫We have our web servers, 60 00:02:03,250 --> 00:02:05,000 ‫and they're taking request, maybe, 61 00:02:05,000 --> 00:02:07,120 ‫through an application load balancer. 62 00:02:07,120 --> 00:02:09,370 ‫They are served through EC2 instances 63 00:02:09,370 --> 00:02:10,860 ‫in an auto scaling group, 64 00:02:10,860 --> 00:02:11,760 ‫and then, for example, 65 00:02:11,760 --> 00:02:15,310 ‫say that our users want us to process some videos. 66 00:02:15,310 --> 00:02:16,980 ‫Then instead of sending it directly 67 00:02:16,980 --> 00:02:18,660 ‫to the video application, 68 00:02:18,660 --> 00:02:23,170 ‫we can instead insert messages into an SQS queue. 69 00:02:23,170 --> 00:02:25,690 ‫And then, we will have a video processing layer 70 00:02:25,690 --> 00:02:29,010 ‫made of an auto scaling group with EC2 instances, 71 00:02:29,010 --> 00:02:31,350 ‫and these EC2 instances will be reading 72 00:02:31,350 --> 00:02:34,570 ‫from the SQS queue and processing our videos. 73 00:02:34,570 --> 00:02:35,720 ‫The cool thing about it 74 00:02:35,720 --> 00:02:38,840 ‫is that we can scale the second auto scaling group 75 00:02:38,840 --> 00:02:40,760 ‫independently from the first one. 76 00:02:40,760 --> 00:02:42,380 ‫And this is why it's called decoupling, 77 00:02:42,380 --> 00:02:43,350 ‫and on top of it, 78 00:02:43,350 --> 00:02:45,790 ‫the scaling can happens based on how many messages, 79 00:02:45,790 --> 00:02:48,390 ‫for example, there are in the SQS queue. 80 00:02:48,390 --> 00:02:51,580 ‫And this would really allow us to have two layers, 81 00:02:51,580 --> 00:02:53,620 ‫the web servers and the video processing, 82 00:02:53,620 --> 00:02:55,620 ‫fully decoupled from the SQS queue, 83 00:02:55,620 --> 00:02:57,340 ‫and scaling independently. 84 00:02:57,340 --> 00:02:59,300 ‫This will give us the best user experience, 85 00:02:59,300 --> 00:03:01,140 ‫and also the best cost efficiency 86 00:03:01,140 --> 00:03:02,480 ‫and scaling concerns. 87 00:03:02,480 --> 00:03:03,550 ‫So I hope you liked this, 88 00:03:03,550 --> 00:03:05,300 ‫I will see you in the next lecture.