1 00:00:01,280 --> 00:00:04,660 We're not going to go back over to our common module and inside of all the different events we have 2 00:00:04,670 --> 00:00:05,600 great inside of here. 3 00:00:05,630 --> 00:00:09,590 We're going to make sure that we communicate the version number inside of these things. 4 00:00:09,590 --> 00:00:14,270 So for example in the case of ticket updated along with some information about the ticket that was just 5 00:00:14,270 --> 00:00:18,380 updated we're also going to include this ticket's version number and that is was going to eventually 6 00:00:18,380 --> 00:00:23,330 help us make sure that we process these events in the correct order before we add in this version number. 7 00:00:23,330 --> 00:00:28,670 However I want to try to answer a question that you might be asking yourself right now that question 8 00:00:28,760 --> 00:00:34,190 might be something like this when should we increment or include the version number of a record with 9 00:00:34,190 --> 00:00:36,080 any event should it be all the time. 10 00:00:36,080 --> 00:00:41,060 Should every single event that ever talks about some record always increment version number or always 11 00:00:41,060 --> 00:00:41,910 included. 12 00:00:41,910 --> 00:00:43,380 Well the answer is No. 13 00:00:43,420 --> 00:00:49,370 We're only going to worry about incrementing or including the version number of a record whenever it 14 00:00:49,370 --> 00:00:55,790 is the primary service responsible for a record that is emitting an event to describe that record either 15 00:00:55,790 --> 00:00:59,470 being created updated or destroyed. 16 00:00:59,470 --> 00:01:03,880 Now this rule alone by itself doesn't really make a lot of sense and I don't think really answers this 17 00:01:03,880 --> 00:01:04,570 question. 18 00:01:04,570 --> 00:01:09,610 So let me just show you a hypothetical scenario back inside of that blog post application that we worked 19 00:01:09,610 --> 00:01:11,680 on much earlier inside this course. 20 00:01:11,680 --> 00:01:16,390 And when we walk through this hypothetical scenario I think you're going to understand this answer a 21 00:01:16,390 --> 00:01:18,990 little bit better OK. 22 00:01:18,990 --> 00:01:24,880 So here's the blog post application we're looking just at the comment service moderation inquiry to 23 00:01:24,930 --> 00:01:26,430 remember how this thing works. 24 00:01:26,430 --> 00:01:31,140 Whenever a user came to the comments service to create a comment we would emit an event of comment created 25 00:01:31,540 --> 00:01:37,600 and that would go over to the moderation service and the query service the moderation service would 26 00:01:37,630 --> 00:01:42,310 then moderate the comment in some way and it would emit an event of comments moderated. 27 00:01:42,520 --> 00:01:48,370 That was only received by the comment service the comment service then process that update events and 28 00:01:48,360 --> 00:01:53,380 they said OK I need to somehow moderate this comment or handle the moderation event and it may have 29 00:01:53,380 --> 00:01:59,530 made a change to the content of the comment the comment service would then emit a follow up event of 30 00:02:00,310 --> 00:02:00,640 comment. 31 00:02:00,640 --> 00:02:06,000 Updated and that would go on down to the query service and the query service then knew. 32 00:02:06,020 --> 00:02:06,270 OK. 33 00:02:06,290 --> 00:02:07,390 This thing has been moderated. 34 00:02:07,400 --> 00:02:09,300 We are all good to go. 35 00:02:09,340 --> 00:02:12,980 That was the flow of events back inside of that blog post application. 36 00:02:13,000 --> 00:02:17,920 Now I want to imagine what would happen if we did not follow this rule right here if we said that any 37 00:02:17,920 --> 00:02:23,490 old service can increment the version number of a record whenever it felt like it. 38 00:02:23,510 --> 00:02:24,350 So here's what would happen. 39 00:02:25,860 --> 00:02:30,390 We can have our comment service and we're going to imagine that this thing is going to publish this 40 00:02:30,390 --> 00:02:36,310 comment created event and it's going to include a version number by default version zero. 41 00:02:36,600 --> 00:02:42,810 That's going to go back to the moderation service and query service now the moderation service will 42 00:02:42,810 --> 00:02:47,430 once again do the moderation and then it's going to MIT comment moderated and we're going to say for 43 00:02:47,430 --> 00:02:50,100 just a moment that we are not going to follow this rule. 44 00:02:50,120 --> 00:02:52,020 It's going to show you what we should not do. 45 00:02:52,020 --> 00:02:54,880 This is not what we want to do at all. 46 00:02:54,920 --> 00:02:58,860 They're going to say that when the moderation service kind of processes this comment the moderation 47 00:02:58,860 --> 00:03:02,510 service might think oh well I've kind of done some processing on this comment. 48 00:03:02,520 --> 00:03:04,410 I've kind of update it in some way. 49 00:03:04,410 --> 00:03:08,010 So you know what I'm going to update the version number and again that's not what we want but let's 50 00:03:08,010 --> 00:03:10,050 just imagine it happens for a second. 51 00:03:10,190 --> 00:03:13,430 So I'd put on a version number of one. 52 00:03:13,460 --> 00:03:16,950 So now this event was processed only by the common service. 53 00:03:16,950 --> 00:03:19,820 Remember that was not processed by the query service at all. 54 00:03:19,820 --> 00:03:22,410 Now the comment service takes a look at that thing. 55 00:03:22,430 --> 00:03:24,050 It says OK the comment was moderated. 56 00:03:24,050 --> 00:03:29,120 I'm going to process this and I say this comment has been moderated and then eventually emit the comment. 57 00:03:29,120 --> 00:03:34,520 Updated events presumably as a part of the comment service processing comment moderated. 58 00:03:34,610 --> 00:03:38,730 It will presumably also see that has a version number of one. 59 00:03:38,750 --> 00:03:44,780 And so when common service emits common updated we're going to assume that in turn it decides to take 60 00:03:44,840 --> 00:03:49,590 that version number add one to it and then emit that as the final update. 61 00:03:49,610 --> 00:03:55,210 So inside Come in updated we would imagine that this thing would have a version of two now think about 62 00:03:55,210 --> 00:03:57,670 this solely from the query service perspective. 63 00:03:57,670 --> 00:04:03,620 We can forget everything else that's going on here and just think about it from the query service perspective 64 00:04:04,130 --> 00:04:08,470 the service has now seen a events of common created and had a version of zero. 65 00:04:08,480 --> 00:04:13,790 So record being created fantastic let's save that record internally inside of query service. 66 00:04:13,790 --> 00:04:19,550 And now the next event that the query service would expect to see should have a version of one but that 67 00:04:19,550 --> 00:04:24,860 never comes because the record that tried to say hey here's version 1 never got received or processed 68 00:04:24,860 --> 00:04:26,360 by the query service. 69 00:04:26,360 --> 00:04:30,500 And so the next event that this thing was received would have a version of to the query service would 70 00:04:30,500 --> 00:04:32,270 say oh obviously on a version one. 71 00:04:32,270 --> 00:04:38,930 So I'm going to reject version two and not process it until I eventually receive an event a version 72 00:04:38,930 --> 00:04:39,520 one. 73 00:04:39,530 --> 00:04:41,880 Well naturally it's never going to receive version 1. 74 00:04:41,930 --> 00:04:47,830 So the query service is now going to be stuck and never be able to process this event right here so 75 00:04:47,860 --> 00:04:53,590 all this could have been prevented if we followed this rule right here and we said that only the primary 76 00:04:53,590 --> 00:04:58,350 service responsible for record is going to be in charge of incrementing a version number. 77 00:04:58,390 --> 00:05:02,900 So if we apply that rule we would have said that the current created event right here at the version 78 00:05:02,920 --> 00:05:08,890 0 moderation service would have sent back comment moderated and it would have not included some incremented 79 00:05:08,890 --> 00:05:11,560 version number it can include the version number. 80 00:05:11,650 --> 00:05:12,370 No problem there. 81 00:05:12,370 --> 00:05:16,930 It can include the version number but we would definitely not have this other service or the service 82 00:05:16,930 --> 00:05:22,170 that is not truly in charge of comments increment the number. 83 00:05:22,310 --> 00:05:26,210 Now the com service would receive comment moderated it would do some processing it would update comment 84 00:05:26,210 --> 00:05:31,220 internally and now the new version number of one common service would emit come an updated would have 85 00:05:31,220 --> 00:05:37,370 a version of one and now query service and see version zero version one no problem let's process this 86 00:05:37,370 --> 00:05:39,220 right here version 1. 87 00:05:39,260 --> 00:05:45,260 So long story short we're gonna make sure that only the service that is responsible for a record like 88 00:05:45,260 --> 00:05:50,480 the actual definition the true canonical definition of ordered a record is is going to be responsible 89 00:05:50,480 --> 00:05:53,870 for incrementing and including that incremented version number. 90 00:05:53,870 --> 00:05:57,740 Now again this diagram here might be just a little bit misleading because I put the word include it 91 00:05:57,740 --> 00:06:02,510 is OK if other services include the version number and as a matter of fact we might want to have them 92 00:06:02,510 --> 00:06:06,680 include that version number as we just saw here at the moderation service told you okay to include the 93 00:06:06,680 --> 00:06:07,430 version number. 94 00:06:07,430 --> 00:06:11,480 What we're really talking about right now is whether or not this other surface increments that version 95 00:06:11,480 --> 00:06:14,480 number and the answer is no not at all okay. 96 00:06:14,480 --> 00:06:16,330 I apologize for the long aside. 97 00:06:16,340 --> 00:06:22,340 But as I mentioned I thought this might be a question you had especially as we go into our common module 98 00:06:22,370 --> 00:06:25,930 and start to include the version number on all these different events. 99 00:06:25,940 --> 00:06:29,330 Let's take a pause right here and actually update this thing in just a moment.