1 00:00:00,150 --> 00:00:07,140 ‫All right, we did the post about the get together, it will be easier, it is to get you get let's 2 00:00:07,140 --> 00:00:08,960 ‫get that thing right. 3 00:00:09,780 --> 00:00:12,120 ‫And what do we do to do it? 4 00:00:12,120 --> 00:00:16,860 ‫Get essentially what we are getting from the server as. 5 00:00:18,890 --> 00:00:21,950 ‫All right, so I'm going to do it fancier this time, right? 6 00:00:21,980 --> 00:00:26,850 ‫So I'm going to use the like that idea. 7 00:00:27,080 --> 00:00:29,570 ‫I think it's going like that is as a call, an ID. 8 00:00:29,570 --> 00:00:35,450 ‫I think so the your ID will be like that will be part of the URL. 9 00:00:35,450 --> 00:00:43,700 ‫So like if you do like to finish localhost eighty, eighty one and then you do like bleb as of now this, 10 00:00:43,880 --> 00:00:47,800 ‫this url now will this will be the oral idea. 11 00:00:47,990 --> 00:00:48,440 ‫Get it. 12 00:00:49,300 --> 00:00:49,790 ‫Get it. 13 00:00:49,790 --> 00:00:50,680 ‫I don't get it. 14 00:00:50,830 --> 00:00:57,180 ‫Guys I have to, I got to spell out everything with you guys shesh or so it goes. 15 00:00:57,200 --> 00:01:04,380 ‫Your idea will be equal request that I think it's called forams thought you ought to lity. 16 00:01:04,400 --> 00:01:05,770 ‫Right then what do you do it this way. 17 00:01:05,780 --> 00:01:07,010 ‫I think I might be wrong. 18 00:01:07,010 --> 00:01:08,060 ‫So we'll check it out. 19 00:01:08,090 --> 00:01:09,420 ‫OK, so you are. 20 00:01:10,190 --> 00:01:10,670 ‫All right. 21 00:01:10,730 --> 00:01:13,340 ‫So we get our idea, which is this this thing. 22 00:01:13,340 --> 00:01:15,540 ‫Right, right. 23 00:01:16,280 --> 00:01:17,690 ‫So what do we do? 24 00:01:17,720 --> 00:01:20,390 ‫We need to query first to do the query. 25 00:01:20,420 --> 00:01:22,880 ‫We need to find which which database to hit. 26 00:01:23,150 --> 00:01:27,290 ‫And to do that, we don't need to hash because we have the hash. 27 00:01:27,560 --> 00:01:27,980 ‫Right. 28 00:01:28,640 --> 00:01:30,680 ‫ARV's, we have the meat. 29 00:01:31,010 --> 00:01:31,460 ‫All right. 30 00:01:31,460 --> 00:01:37,940 ‫So we do that because get the you all get a server and once you get the server. 31 00:01:40,120 --> 00:01:46,700 ‫Now we know it's over, we know which clients, so we essentially do this right. 32 00:01:47,160 --> 00:01:50,020 ‫Easy, easy peasy Japanese. 33 00:01:50,990 --> 00:01:52,240 ‫So we don't need this. 34 00:01:52,600 --> 00:01:57,080 ‫We just need to query and select star again. 35 00:01:57,110 --> 00:01:58,580 ‫Never do this right. 36 00:01:59,290 --> 00:02:01,450 ‫Never, ever, ever do this. 37 00:02:01,690 --> 00:02:05,560 ‫Your tables at what's called a zero table table. 38 00:02:06,130 --> 00:02:11,710 ‫Oh, so select start from your old table where you are already is equal to. 39 00:02:13,040 --> 00:02:15,230 ‫One, thank God. 40 00:02:16,580 --> 00:02:18,660 ‫What's his name, this guy who built this library? 41 00:02:18,680 --> 00:02:19,760 ‫I think his name is Brian. 42 00:02:20,480 --> 00:02:22,400 ‫Brilliant guy, man following Twitter. 43 00:02:23,450 --> 00:02:24,230 ‫Brilliant guy. 44 00:02:24,350 --> 00:02:32,870 ‫OK, so what we do you already I want to give you that so you don't have to do that nasty single codes 45 00:02:32,870 --> 00:02:39,170 ‫and that bad that that you don't have to do that because you'll be you'll be sequel injected. 46 00:02:39,170 --> 00:02:43,730 ‫And by the way, we talked about single injection because I talk about everything I want to learn in 47 00:02:43,730 --> 00:02:47,430 ‫this job, because I want my goals to become better software engineer every day. 48 00:02:47,480 --> 00:02:51,930 ‫So anything that I don't know, essentially I make a video about it, I learn it and I make a video 49 00:02:51,950 --> 00:02:52,130 ‫on it. 50 00:02:52,130 --> 00:02:52,960 ‫So it's like one direction. 51 00:02:53,120 --> 00:02:53,740 ‫Go check it out. 52 00:02:54,470 --> 00:02:56,620 ‫OK, we have our stuff. 53 00:02:56,960 --> 00:03:00,740 ‫What about we actually check this stuff out? 54 00:03:00,740 --> 00:03:02,960 ‫OK, so get this, get the results. 55 00:03:02,960 --> 00:03:05,200 ‫And I think I waited that thing. 56 00:03:05,540 --> 00:03:08,030 ‫The results have a roseau of results. 57 00:03:08,030 --> 00:03:12,880 ‫But Rose, I think it's called the real count. 58 00:03:14,220 --> 00:03:14,810 ‫Is it great. 59 00:03:14,810 --> 00:03:16,080 ‫And then zero. 60 00:03:17,240 --> 00:03:19,850 ‫Then we just send back the result, I guess. 61 00:03:20,870 --> 00:03:25,640 ‫And then if there is no results, what's the status code for something that is not found? 62 00:03:26,090 --> 00:03:34,640 ‫Good for over Sinda status since since status for all for those four four. 63 00:03:34,910 --> 00:03:38,120 ‫Because it's not found if it's found that I'm going to return this thing. 64 00:03:38,990 --> 00:03:39,440 ‫Right. 65 00:03:39,470 --> 00:03:43,010 ‫And what do you do already by else? 66 00:03:43,010 --> 00:03:43,430 ‫Elseworlds. 67 00:03:47,800 --> 00:03:54,610 ‫All right, so your ID let's just do the same exact thing so we don't mess up right, stay consistent, 68 00:03:55,450 --> 00:03:59,050 ‫consistent hashing babes, I say your it is is the same one. 69 00:03:59,050 --> 00:03:59,620 ‫I don't really care. 70 00:03:59,640 --> 00:04:02,680 ‫I want this guy and he tells me which server. 71 00:04:02,860 --> 00:04:04,620 ‫I want you to pick that thing up. 72 00:04:05,170 --> 00:04:05,770 ‫All right. 73 00:04:06,130 --> 00:04:07,920 ‫Looks like it's Wardo. 74 00:04:09,960 --> 00:04:10,270 ‫But. 75 00:04:12,400 --> 00:04:16,330 ‫Do it, do it only valid in async function. 76 00:04:16,360 --> 00:04:18,640 ‫Yes, sir, because I forgot to add async here. 77 00:04:20,250 --> 00:04:20,880 ‫And Gil. 78 00:04:23,940 --> 00:04:24,310 ‫All right. 79 00:04:25,590 --> 00:04:26,110 ‫Whoo! 80 00:04:26,760 --> 00:04:30,210 ‫Let's do this, get well, get it easy, just do this. 81 00:04:31,140 --> 00:04:33,650 ‫And now I need something that actually exists, right? 82 00:04:33,690 --> 00:04:35,360 ‫This is not found this funny. 83 00:04:35,360 --> 00:04:36,520 ‫It actually not sound. 84 00:04:36,540 --> 00:04:43,470 ‫Right, because it now is going to return for me and for forever because this dusa doesn't exist. 85 00:04:43,590 --> 00:04:46,260 ‫So that doesn't exist for all. 86 00:04:46,260 --> 00:04:46,860 ‫For not found. 87 00:04:46,920 --> 00:04:49,530 ‫OK, how about we find something that is actually there. 88 00:04:49,770 --> 00:04:53,450 ‫OK, so if I go to any server I just pick up any services. 89 00:04:53,450 --> 00:04:55,530 ‫Seshadri three the search server. 90 00:04:55,540 --> 00:04:59,070 ‫If you do this right, it's not working. 91 00:04:59,400 --> 00:05:02,970 ‫Or they might have some bugs. 92 00:05:02,970 --> 00:05:07,440 ‫Guys, that's going to check what's going on. 93 00:05:08,470 --> 00:05:09,800 ‫It hit it. 94 00:05:10,350 --> 00:05:11,350 ‫Did I get this right. 95 00:05:11,790 --> 00:05:14,220 ‫Yes, I get it in HCM seven. 96 00:05:14,230 --> 00:05:14,510 ‫Right. 97 00:05:14,700 --> 00:05:19,260 ‫And if I do that, I'm going to get its citizens server five, four, three, two. 98 00:05:19,440 --> 00:05:28,710 ‫And if I query right and I get rows count zero row count, there's no rows count, it's row count plus 99 00:05:28,740 --> 00:05:30,710 ‫even though I didn't get any rows back. 100 00:05:30,730 --> 00:05:30,950 ‫Right. 101 00:05:31,380 --> 00:05:31,890 ‫So let's see. 102 00:05:31,890 --> 00:05:34,140 ‫What would it what are we doing wrong here, guys? 103 00:05:34,410 --> 00:05:41,760 ‫All right, guys, I had to post the video where you found the big, huge bug on one of the implementation 104 00:05:41,760 --> 00:05:45,390 ‫of the old library, the consistent tache library. 105 00:05:45,390 --> 00:05:51,510 ‫For some reason when I practiced this video, I didn't hit it, but I had it during this video while 106 00:05:51,510 --> 00:05:52,620 ‫recording this video. 107 00:05:53,640 --> 00:05:59,250 ‫And apparently that hash ring thing, that consistent hash was not giving me the same value. 108 00:05:59,370 --> 00:06:01,230 ‫So it was stupid and useless. 109 00:06:01,500 --> 00:06:03,110 ‫It's just buggy implementation. 110 00:06:03,450 --> 00:06:06,720 ‫So I found another library called Hasharon, which is a correct implementation. 111 00:06:06,720 --> 00:06:08,310 ‫Finally, it's exactly the same. 112 00:06:09,070 --> 00:06:09,410 ‫Right. 113 00:06:09,480 --> 00:06:11,760 ‫So you're going to add the same thing or add this. 114 00:06:11,760 --> 00:06:15,510 ‫But now when I do, I get right with a key. 115 00:06:15,860 --> 00:06:16,550 ‫It's the same thing. 116 00:06:16,560 --> 00:06:17,840 ‫Exactly right. 117 00:06:17,850 --> 00:06:21,390 ‫It gives me the same value every time because that's what I want. 118 00:06:21,390 --> 00:06:26,390 ‫I don't want it to give me a random values that defeats the purpose of a consistent hash line. 119 00:06:26,790 --> 00:06:28,950 ‫I don't know what that implementation was about. 120 00:06:29,250 --> 00:06:29,630 ‫Right. 121 00:06:29,640 --> 00:06:30,270 ‫So I checked. 122 00:06:30,900 --> 00:06:32,790 ‫It wasn't updated for four years. 123 00:06:32,790 --> 00:06:34,200 ‫I was a bad idea for myself. 124 00:06:34,200 --> 00:06:35,060 ‫I apologize. 125 00:06:35,340 --> 00:06:40,350 ‫So the rest of the video will use this hash ring instead of the consistent dash hash. 126 00:06:40,620 --> 00:06:40,990 ‫Right. 127 00:06:41,100 --> 00:06:42,120 ‫I apologize for that. 128 00:06:42,120 --> 00:06:43,770 ‫But it's the same implementation, right? 129 00:06:43,770 --> 00:06:44,660 ‫The same idea. 130 00:06:44,790 --> 00:06:47,670 ‫Nothing changed that code will the latest code will use the hash. 131 00:06:48,120 --> 00:06:54,240 ‫So now if I actually so I go I went and then translated all the arrows on my oh my short. 132 00:06:54,390 --> 00:06:58,430 ‫Repopulated it with a brand new set of IDs. 133 00:06:58,680 --> 00:06:58,870 ‫Right. 134 00:06:58,930 --> 00:06:59,520 ‫So now. 135 00:07:00,420 --> 00:07:02,400 ‫I go back to get right here. 136 00:07:03,610 --> 00:07:10,590 ‫If I do like let's say I went back here and it's like, OK, Shahid, what, I'm short three and I want 137 00:07:11,460 --> 00:07:12,690 ‫E for RJ. 138 00:07:12,840 --> 00:07:14,670 ‫So this is what shot three, right. 139 00:07:15,030 --> 00:07:15,990 ‫Shot three. 140 00:07:16,170 --> 00:07:16,740 ‫And I did. 141 00:07:16,750 --> 00:07:22,110 ‫OK, go ahead and show me that for that Eid. 142 00:07:23,370 --> 00:07:25,260 ‫I get back at 3:00, right? 143 00:07:25,500 --> 00:07:32,110 ‫So let's go ahead to actually Shahd, one of the heroes and short one, OK, and let's check that out. 144 00:07:33,210 --> 00:07:34,740 ‫Do we give the values here? 145 00:07:35,160 --> 00:07:37,020 ‫So, yeah, there's a bunch of values here. 146 00:07:37,200 --> 00:07:40,590 ‫Pick one of them and then M.C. eight, seven, five. 147 00:07:40,620 --> 00:07:41,560 ‫I do that. 148 00:07:41,580 --> 00:07:41,900 ‫Right. 149 00:07:42,030 --> 00:07:43,430 ‫Let's just refresh that thing. 150 00:07:43,860 --> 00:07:44,270 ‫Right. 151 00:07:44,280 --> 00:07:46,320 ‫And if I do, give me that. 152 00:07:48,000 --> 00:07:50,470 ‫I'm going to Head Start one, five, four, three, two. 153 00:07:50,490 --> 00:07:52,560 ‫That's exactly what we want, right? 154 00:07:52,950 --> 00:07:54,570 ‫Powerful stuff, right? 155 00:07:54,870 --> 00:07:57,840 ‫So once we get that, I know which server to go right. 156 00:07:57,850 --> 00:08:01,530 ‫So let's go ahead and complete the query and add all that jazz. 157 00:08:01,530 --> 00:08:01,700 ‫Right. 158 00:08:01,740 --> 00:08:02,640 ‫So let's go ahead. 159 00:08:03,330 --> 00:08:05,130 ‫So we get the results back from the query. 160 00:08:05,460 --> 00:08:05,770 ‫Right. 161 00:08:06,060 --> 00:08:14,940 ‫If the result door row count, I think is called greater than zero, then I want to send back obviously 162 00:08:14,940 --> 00:08:16,380 ‫this results right, guys? 163 00:08:17,340 --> 00:08:20,760 ‫And I want to actually just send the rules back. 164 00:08:20,790 --> 00:08:21,140 ‫Right. 165 00:08:21,150 --> 00:08:22,360 ‫Just go ahead and send it. 166 00:08:22,680 --> 00:08:23,460 ‫We can just do. 167 00:08:24,750 --> 00:08:29,490 ‫Because we're going to get one roll back, right, this implementation, by the way, guys could have 168 00:08:29,490 --> 00:08:30,660 ‫duplicates, right? 169 00:08:30,680 --> 00:08:33,420 ‫I didn't account for duplicate, but it's easy to fix. 170 00:08:33,730 --> 00:08:34,040 ‫Right. 171 00:08:34,260 --> 00:08:35,570 ‫I'm not going to fix it here. 172 00:08:35,580 --> 00:08:38,400 ‫Obviously, this is a Sharding video, not a whole. 173 00:08:38,400 --> 00:08:41,610 ‫The URL shortener design course, Ryan. 174 00:08:41,640 --> 00:08:43,030 ‫So you are sure to get it. 175 00:08:43,110 --> 00:08:44,200 ‫Give me the idea. 176 00:08:44,200 --> 00:08:45,200 ‫I'm going to get the oil. 177 00:08:45,210 --> 00:08:46,310 ‫How do I get the oil? 178 00:08:46,920 --> 00:08:47,670 ‫I can do this. 179 00:08:47,670 --> 00:08:48,150 ‫Rose. 180 00:08:48,300 --> 00:08:52,220 ‫Sub-Zero and let's just do Sub-Zero. 181 00:08:52,230 --> 00:08:53,910 ‫I don't know the actual values there. 182 00:08:53,910 --> 00:08:54,930 ‫So I'm that server. 183 00:08:55,650 --> 00:09:04,440 ‫And then if it doesn't if you couldn't find it, we said we're going to do respons DOD send status 404. 184 00:09:05,130 --> 00:09:07,740 ‫OK, that is coolish. 185 00:09:07,740 --> 00:09:08,280 ‫Let's do it. 186 00:09:09,320 --> 00:09:12,850 ‫And let's just remove that breakpoint so it doesn't get annoying. 187 00:09:13,400 --> 00:09:15,350 ‫Oh, look at that, we got it. 188 00:09:15,370 --> 00:09:20,600 ‫It's already 40 and it's from server this and all that jazz. 189 00:09:20,600 --> 00:09:20,850 ‫Right. 190 00:09:21,140 --> 00:09:23,810 ‫So how about we pick another one? 191 00:09:24,140 --> 00:09:25,700 ‫Another one, the jihadist. 192 00:09:26,930 --> 00:09:35,600 ‫That's the same server, that's what we pick up, another server, another server, and that's when 193 00:09:35,600 --> 00:09:37,330 ‫I truncated those tables. 194 00:09:37,340 --> 00:09:38,900 ‫Let's go to. 195 00:09:38,970 --> 00:09:39,530 ‫How about that? 196 00:09:39,620 --> 00:09:42,080 ‫Let's pick something from short to do. 197 00:09:42,110 --> 00:09:45,820 ‫We prove that actually this -- is working, right. 198 00:09:51,300 --> 00:09:56,250 ‫Look at that shot, two, five, four, three, three, and we picked out a result of that, so I spread 199 00:09:56,250 --> 00:10:03,200 ‫out my databases and now my rose on my tables and now I'm always getting that stuff back. 200 00:10:03,450 --> 00:10:07,500 ‫Powerful stuff so we know how to write, how to read. 201 00:10:07,680 --> 00:10:10,420 ‫And that's essentially the basics of starting. 202 00:10:10,500 --> 00:10:10,700 ‫Right. 203 00:10:10,830 --> 00:10:13,050 ‫And now what if I do something that doesn't exist? 204 00:10:13,050 --> 00:10:19,090 ‫I get enough on the meter that just blew through. 205 00:10:20,480 --> 00:10:21,350 ‫Not found. 206 00:10:21,500 --> 00:10:21,810 ‫Right. 207 00:10:22,220 --> 00:10:31,090 ‫So a very basic implementation of a Yorka shortener with sharding giving to you guys, right. 208 00:10:31,130 --> 00:10:31,950 ‫Hope you enjoy it. 209 00:10:31,970 --> 00:10:32,690 ‫It's the cold. 210 00:10:32,690 --> 00:10:35,020 ‫It'll be in the description below. 211 00:10:35,270 --> 00:10:36,770 ‫And so it's not that bad, right? 212 00:10:37,220 --> 00:10:45,200 ‫Like for Sharding, that's a pretty cool if you think about it right now, guys, adding shards is not 213 00:10:45,200 --> 00:10:46,210 ‫something easy. 214 00:10:46,220 --> 00:10:51,420 ‫You cannot just add any sharp because you have to really be careful what you're doing right. 215 00:10:51,440 --> 00:10:53,350 ‫You have to be careful with the algorithm. 216 00:10:53,750 --> 00:10:57,900 ‫So the one I did is like it's fixed to that number of schadt, right? 217 00:10:58,250 --> 00:11:03,200 ‫So the moment I add a new shot is going to redistribute and everything is going to go to F, right. 218 00:11:03,380 --> 00:11:06,950 ‫So you really need to know what you're doing with this sharding. 219 00:11:06,960 --> 00:11:09,110 ‫A ratio is a different topic. 220 00:11:09,310 --> 00:11:13,120 ‫It's one of the disadvantages, actually, of of sharding. 221 00:11:13,210 --> 00:11:13,690 ‫All right. 222 00:11:14,240 --> 00:11:14,900 ‫So that's it. 223 00:11:15,080 --> 00:11:19,640 ‫Let's just jump back and do the slides and talk about the pros and cons of sharding.