1 00:00:00,630 --> 00:00:05,130 In the last section we changed up our e-mail template to make sure that whenever a user clicks on a 2 00:00:05,130 --> 00:00:11,130 given survey we get communication through our cell grid web look of exactly what survey the user was 3 00:00:11,130 --> 00:00:15,290 responding to and whether or not they clicked on the yes or the no buttons. 4 00:00:15,660 --> 00:00:21,170 Now we are receiving an array of these events from our censored web hook. 5 00:00:21,300 --> 00:00:25,890 So we need to now think about how we're going to iterate through this list of events find the correct 6 00:00:25,890 --> 00:00:31,550 surveys and then add to their yes or no property to say hey here's some additional amount of feedback. 7 00:00:31,710 --> 00:00:35,940 Now before we start to iterate through this list of all these different events here I want to tell you 8 00:00:35,940 --> 00:00:41,490 about some different weaknesses that we might have inside of our code base right now or maybe a better 9 00:00:41,490 --> 00:00:46,740 way to put it would be some possible pitfalls we could run into as we start to process this list of 10 00:00:46,740 --> 00:00:48,270 events right here. 11 00:00:48,270 --> 00:00:54,360 So the first thing I want to do just to prove a point to you just to give you a demonstration of a possible 12 00:00:54,360 --> 00:01:00,030 pitfall or possible gotcha that we might run into I'm going to go back over to my email account right 13 00:01:00,030 --> 00:01:00,470 here. 14 00:01:00,600 --> 00:01:04,690 So here's the survey that I just clicked on and in very quick succession. 15 00:01:04,710 --> 00:01:07,670 I'm going to click on yes two times in a row. 16 00:01:08,250 --> 00:01:10,070 So I just clicked on yes two times in a row. 17 00:01:10,110 --> 00:01:14,460 Now we're going to flip back over to the terminal and wait for that web hook to pop up on the screen 18 00:01:14,460 --> 00:01:15,540 just a little bit. 19 00:01:15,780 --> 00:01:20,910 When we get the Web hook to actually console log over here again you're going to notice that the web 20 00:01:21,090 --> 00:01:24,710 contains two separate events one event. 21 00:01:24,720 --> 00:01:28,370 First the first click and then the separte that for the second click. 22 00:01:28,380 --> 00:01:33,840 Now remember it's really important inside of our application to make sure that we only ever allow a 23 00:01:33,840 --> 00:01:39,990 user to vote one time on any given survey to make sure that that really happened to make sure that was 24 00:01:39,990 --> 00:01:41,540 100 percent the case. 25 00:01:41,700 --> 00:01:45,050 We had put together that sub document collection of recipients. 26 00:01:45,120 --> 00:01:51,390 Remember we said that every recipient had an e-mail property and a voted property or something like 27 00:01:51,390 --> 00:01:56,640 that to track whether or not a user had voted or in particular someone with that particular e-mail had 28 00:01:56,640 --> 00:01:58,820 voted on a particular survey. 29 00:01:58,830 --> 00:02:02,990 So we do have that kind of prevention layer inside of our application right now. 30 00:02:03,000 --> 00:02:10,800 We've got something to say hey make sure people can't do duplicate votes how ever even with that system 31 00:02:10,830 --> 00:02:12,360 in mind. 32 00:02:12,360 --> 00:02:14,810 And here's my console logs those two clicks I just did. 33 00:02:14,970 --> 00:02:21,540 You'll notice that I've gotten identical e-mail in both them and in identical you are out. 34 00:02:21,630 --> 00:02:26,610 So even though we've got that type of system in place to kind of make sure that the user is not allowed 35 00:02:26,610 --> 00:02:32,670 to vote multiple times I'm still kind of afraid that as we start to process this list of events right 36 00:02:32,670 --> 00:02:40,620 here we might get ourselves into some case where we accidentally say maybe increment the number of yes 37 00:02:40,710 --> 00:02:45,920 responses that we have on a survey and then save that to let you know and then mark that recipients 38 00:02:45,930 --> 00:02:46,990 haven't answered. 39 00:02:47,130 --> 00:02:53,760 And then simultaneously like at the exact same time we might accidentally also process the second event 40 00:02:53,760 --> 00:02:59,790 right here and also start to and comment that yes vote on the survey and also Mark that recipient as 41 00:02:59,790 --> 00:03:05,190 having answered in other words you never know you might get into some type of race condition where you 42 00:03:05,190 --> 00:03:07,730 start to accidentally modify one record. 43 00:03:07,980 --> 00:03:12,960 As we were modifying or as we're about to reach and modify it a second time. 44 00:03:12,960 --> 00:03:18,060 Basically all I mean to say is that before we start to process this list of events I think that we should 45 00:03:18,060 --> 00:03:24,060 do a little preprocessing step on it and make sure that we somehow remove any duplicate results. 46 00:03:24,060 --> 00:03:30,570 In other words any duplicate clicks where a record or two events inside of here have identical e-mail 47 00:03:30,600 --> 00:03:32,150 and identical you or else. 48 00:03:32,430 --> 00:03:37,560 So this is something that is not necessarily you know super necessary inside of an application like 49 00:03:37,560 --> 00:03:39,890 we're talking about a real edge case right here. 50 00:03:40,050 --> 00:03:45,840 But I just mean to suggest that just to code very defensively here just to assume that maybe this web 51 00:03:45,840 --> 00:03:50,940 poll is going to be acting funny sometimes Let's do some filtering ahead of time and make sure that 52 00:03:50,940 --> 00:03:54,570 we do remove any duplicate clicks out of this. 53 00:03:54,570 --> 00:03:58,620 Now there's one other thing I want to mention here about this pre-processing step that we might want 54 00:03:58,620 --> 00:03:59,510 to do. 55 00:03:59,520 --> 00:04:05,340 You'll remember that when we put together the web configuration on the second grid Council we had specifically 56 00:04:05,340 --> 00:04:08,620 said only notify us about click events. 57 00:04:08,620 --> 00:04:15,000 So like whenever a user clicks on an event only notify us about those. 58 00:04:15,000 --> 00:04:21,360 So we can very easily or at least I can I can very easily imagine a situation where maybe some other 59 00:04:21,360 --> 00:04:27,210 developer goes into our Send grid console and accidentally starts tweaking around some stuff on the 60 00:04:27,210 --> 00:04:31,130 web poke stuff and maybe they say Oh Wolf for this other feature I'm working on. 61 00:04:31,140 --> 00:04:35,530 I also want to know about whenever an e-mail bounces or something like that. 62 00:04:35,610 --> 00:04:42,090 And so I personally can very easily imagine a case in which we start to get event objects inside of 63 00:04:42,090 --> 00:04:45,780 this callback that are not of type event click. 64 00:04:45,780 --> 00:04:52,240 So in addition for this preprocessing step I think that we should also make sure that we only feel or 65 00:04:52,260 --> 00:04:56,980 that we filter out to some degree only events that are of type click. 66 00:04:57,060 --> 00:05:02,930 Because even though we are only asking grade for click events right now I can again I can really imagine 67 00:05:02,930 --> 00:05:07,340 a case in which some other developer accidentally starts messing around with our Send grid settings 68 00:05:07,640 --> 00:05:11,430 and we start getting event objects in here with a type other than click. 69 00:05:11,480 --> 00:05:14,090 So that's another thing that I think we should be really aware of. 70 00:05:14,090 --> 00:05:21,470 And the last thing I want to be aware of even if it a event object in here has type click I can again 71 00:05:21,470 --> 00:05:27,770 really imagine a case where we might start putting two other links inside of our e-mails so maybe we 72 00:05:27,770 --> 00:05:35,240 also provide a user a link to like some terms of service or to our Web page of email dot com or something 73 00:05:35,240 --> 00:05:36,150 like that. 74 00:05:36,170 --> 00:05:43,670 And so even if a event object inside of it is of type click I can also imagine a case where we start 75 00:05:43,670 --> 00:05:50,570 getting you or else that don't strictly follow this API slash surveys survey ID slash Yes type of schema 76 00:05:50,960 --> 00:05:57,050 maybe at some point if we also put in a link to our home page we might see events with type of click 77 00:05:57,110 --> 00:06:03,140 that have a U or l of w w w dot e mail dot com or something like that. 78 00:06:03,170 --> 00:06:08,930 So that's a couple of different situations in which I can very easily imagine that this list of events 79 00:06:08,930 --> 00:06:13,730 that we get back from Send grid's starts to have some data that doesn't strictly conform to what we 80 00:06:13,730 --> 00:06:15,110 are expecting it to. 81 00:06:15,110 --> 00:06:20,090 And so again I think that we really need to do some amount of pre-processing to make sure that we don't 82 00:06:20,120 --> 00:06:27,350 accidentally say whoa here's this crazy object of type like bounce and it doesn't have a u r l or maybe 83 00:06:27,350 --> 00:06:32,480 it's the event object of type click and it does have a U or L but it doesn't have a survey ID inside 84 00:06:32,480 --> 00:06:32,930 of it. 85 00:06:32,930 --> 00:06:38,510 So again I think that we need to write our logic for our request handler for handling this website. 86 00:06:38,590 --> 00:06:44,570 Well put stuff in a very defensive fashion and kind of just assume that we might be getting a lot of 87 00:06:44,570 --> 00:06:46,730 junk data inside of there. 88 00:06:46,760 --> 00:06:50,180 So with all that in mind I want to take a break right now. 89 00:06:50,330 --> 00:06:56,000 When we come back in the next section now that we understand why we might want to do some type of pre-processing 90 00:06:56,020 --> 00:06:57,300 or filtering step. 91 00:06:57,450 --> 00:07:02,360 Honestly that list I want to come back in the next section and talk about exactly how we're going to 92 00:07:02,360 --> 00:07:04,530 do this sort of processing pipeline. 93 00:07:04,550 --> 00:07:08,390 Before we start to actually mess with any surveys that are in our database. 94 00:07:08,390 --> 00:07:09,700 So let's take a quick break. 95 00:07:09,710 --> 00:07:14,430 We'll come back in the next section and talk about how we are going to put this pipeline together.