1 00:00:00,970 --> 00:00:04,930 We were just taking a look at options or two and we eventually said that the issue with this approach 2 00:00:05,140 --> 00:00:09,940 is that we are allowing our query service to have a very deep understanding of what this comment moderated 3 00:00:09,940 --> 00:00:11,210 event is. 4 00:00:11,350 --> 00:00:17,170 So to solve this we're going to have a comment moderated b instead processed by the comments service. 5 00:00:17,170 --> 00:00:19,950 Let me show you how this is going to work out OK. 6 00:00:20,290 --> 00:00:25,060 So in this diagram on the left hand side we've got our comment service and the query service the comment 7 00:00:25,060 --> 00:00:31,270 service is the service that is ultimately in charge of exactly what a comment is and knows all the very 8 00:00:31,270 --> 00:00:37,450 precise business rules all the business logic everything around what a comment is how to update it and 9 00:00:37,450 --> 00:00:39,580 how to deal with it in some way. 10 00:00:39,580 --> 00:00:44,350 And so it makes a lot of sense to have our comment service be the one that is responsible for some very 11 00:00:44,350 --> 00:00:50,770 precise very well calibrated way of updating a comment whenever the comment service updates a comment 12 00:00:50,890 --> 00:00:53,430 by handling one of these very specialized events. 13 00:00:53,590 --> 00:01:02,020 We're going to have it emit one single very generic event called simply comment updated whereas all 14 00:01:02,020 --> 00:01:06,790 the events on the left hand side meant that we wanted to update a common in some very specific way that 15 00:01:06,830 --> 00:01:11,980 come an updated event says hey there's a new comment right here or a new version of this comment. 16 00:01:12,010 --> 00:01:13,870 Don't worry about what the update was. 17 00:01:13,870 --> 00:01:15,610 Don't worry about trying to interpret it. 18 00:01:15,670 --> 00:01:18,760 Don't worry about trying to run some specialized business logic around it. 19 00:01:18,910 --> 00:01:22,360 Just take these updated attributes and store them if you need them. 20 00:01:23,230 --> 00:01:28,020 So we're gonna follow this pattern throughout all the services we've put together the service that is 21 00:01:28,020 --> 00:01:33,720 in charge of a basic resource will be in charge of these various specialized updates and any time those 22 00:01:33,720 --> 00:01:41,720 specialized updates occur that service will emit a very generic event update so let's take a look at 23 00:01:41,720 --> 00:01:45,800 what this is going to look like for the services we are talking about right now. 24 00:01:45,890 --> 00:01:50,780 So we're going to once again have a user submitted comment as soon as they do so we're going to have 25 00:01:50,810 --> 00:01:56,480 our comments service versus that event and notably you'll notice that it now knows the status of that 26 00:01:56,480 --> 00:01:57,520 comment as well. 27 00:01:59,410 --> 00:02:05,090 The comment service will then continue to emit a comment created event that will go to the event bus 28 00:02:05,570 --> 00:02:10,850 it will go off to our moderation service and to the query service as well. 29 00:02:10,850 --> 00:02:14,510 So we're going to still solve that issue we ran into earlier where the query service didn't really know 30 00:02:14,510 --> 00:02:17,030 that a comment was created. 31 00:02:17,030 --> 00:02:21,230 And so that was where we ran into issues with the user submitted comment and then refreshing the page 32 00:02:23,330 --> 00:02:28,970 were then going to make sure that the moderation service still processes that comment and moderates 33 00:02:28,970 --> 00:02:30,360 it in some way. 34 00:02:30,420 --> 00:02:35,810 So that's going to go off to our event bus and now it's only going to go over to the comments service 35 00:02:37,200 --> 00:02:42,390 the comment service will be the only thing that knows how to process this very specialized update to 36 00:02:42,390 --> 00:02:43,650 what a comment is. 37 00:02:44,190 --> 00:02:51,150 So in this case we'll change the status around pending to approved then because the comment Service 38 00:02:51,150 --> 00:02:57,720 just made a change to a comment a very specialized very domain specific change that will then you missed 39 00:02:58,050 --> 00:02:58,680 a comment. 40 00:02:58,680 --> 00:02:59,940 Updated event. 41 00:02:59,940 --> 00:03:01,770 So this is a very generic event. 42 00:03:01,770 --> 00:03:04,180 It just says Hey some attributes change. 43 00:03:04,200 --> 00:03:05,970 Don't worry about what changed. 44 00:03:05,970 --> 00:03:07,970 Don't worry about processing this in any way. 45 00:03:07,980 --> 00:03:14,100 Just use these attributes if you care about it at all that will go off to the event bus the event plus 46 00:03:14,100 --> 00:03:16,030 we'll send it off to the query service. 47 00:03:16,030 --> 00:03:19,020 And now the query service is going to say oh a comment was updated. 48 00:03:19,020 --> 00:03:22,200 I don't care how or why it was updated. 49 00:03:22,200 --> 00:03:28,980 I'm just going to take all the different properties out of that event and I'm going to use those as 50 00:03:28,980 --> 00:03:32,960 the basis for my new comment or for update this comment. 51 00:03:32,960 --> 00:03:35,760 We're not going to necessarily just change that status flag. 52 00:03:35,760 --> 00:03:40,350 We're just going to say take all those attributes and use them to update our existing comment. 53 00:03:40,380 --> 00:03:42,340 That's it. 54 00:03:42,350 --> 00:03:47,000 Now I know that this might seem a little bit challenging to understand this idea of having a domain 55 00:03:47,000 --> 00:03:49,060 specific event in a very generic event. 56 00:03:49,160 --> 00:03:52,240 Well you're going to see many examples of this on the later project. 57 00:03:52,250 --> 00:03:53,080 We work on as well. 58 00:03:53,120 --> 00:03:56,450 So don't worry you'll get a lot of experience with this over time. 59 00:03:56,630 --> 00:03:58,670 So that's what we're gonna do inside of our application. 60 00:03:58,680 --> 00:04:00,960 We are going to use option number three. 61 00:04:00,960 --> 00:04:03,100 We're going to end up introducing two events. 62 00:04:03,110 --> 00:04:07,430 One is going to be very specialized in nature that is going to be the comment moderated event. 63 00:04:07,550 --> 00:04:12,170 It's going to be process by comment service and then as soon as comment service updates that comment 64 00:04:12,200 --> 00:04:16,520 it's going to emit that generic event to say hey this comment was just updated. 65 00:04:16,520 --> 00:04:20,550 If you care about it great use it in some way. 66 00:04:20,560 --> 00:04:26,080 Now the upside to this approach is that the query service only needs to know about common updated even 67 00:04:26,080 --> 00:04:31,900 if we start to add in a billion different ways of exactly how we can precisely update a comment query 68 00:04:31,900 --> 00:04:36,190 service doesn't need to know that it just needs to know oh this comment was updated on is going to take 69 00:04:36,190 --> 00:04:38,930 these attributes and use them OK. 70 00:04:38,950 --> 00:04:41,150 So now we understand what we're going to do inside of our application. 71 00:04:41,150 --> 00:04:45,610 We'll take a quick pause right here and start to implement option or three in just a moment.