1 00:00:00,210 --> 00:00:02,010 ‫What is going on, guys? 2 00:00:02,040 --> 00:00:06,150 ‫My name is Hossein, and in this video I want to build with you guys a U. 3 00:00:06,150 --> 00:00:07,190 ‫RL shortener. 4 00:00:07,200 --> 00:00:15,360 ‫So we're going to go through a system design to interview questions or this is one of the most interesting 5 00:00:15,360 --> 00:00:15,900 ‫ones, right? 6 00:00:15,930 --> 00:00:19,260 ‫It's very common and it's really easy to build. 7 00:00:19,740 --> 00:00:27,480 ‫But before we jump into the video, guys, I want you to always for any of these exercises, design 8 00:00:27,480 --> 00:00:34,710 ‫system design, you are the system designer, and I want you to treat whatever this is. 9 00:00:34,920 --> 00:00:43,260 ‫This is the blank canvas that you put your own unique design in, OK? 10 00:00:43,770 --> 00:00:44,190 ‫And. 11 00:00:45,130 --> 00:00:50,460 ‫Be proud of whatever you put in there, because it is an art, right? 12 00:00:50,500 --> 00:00:52,760 ‫I consider system design as an art. 13 00:00:52,780 --> 00:00:58,720 ‫Some people might not agree, but there are literally thousands and thousands and thousands of way to 14 00:00:58,720 --> 00:01:00,520 ‫solve any given problem. 15 00:01:00,520 --> 00:01:02,600 ‫And today's problem is you are the shortener. 16 00:01:02,770 --> 00:01:06,570 ‫So whatever I'm going to come up with is not going to be perfect. 17 00:01:06,580 --> 00:01:14,380 ‫Whenever a 30 year experience professional either is not perfect because there is always pros and cons 18 00:01:14,380 --> 00:01:18,570 ‫for every system design and whatever you come up with on it. 19 00:01:18,760 --> 00:01:26,440 ‫Enjoy the process because it's going to be your baby and it feels damn good if you design something 20 00:01:26,440 --> 00:01:33,790 ‫of your own without actually looking through the best practices right before you jump into best practices, 21 00:01:33,970 --> 00:01:38,820 ‫just do something, do a bad design and start to improve it. 22 00:01:39,100 --> 00:01:41,560 ‫Keep in mind that everything can be improved. 23 00:01:41,950 --> 00:01:48,040 ‫Well, that said, how about we jump into the video and start building our all your own show? 24 00:01:48,280 --> 00:01:48,760 ‫So what is it? 25 00:01:48,760 --> 00:01:57,040 ‫You know, it's a system that you give me a whole large euro and I'm making it into a tiny URL. 26 00:01:57,250 --> 00:02:02,740 ‫And if you give me that tiny URL, I'm going to give you or redirect back to the original. 27 00:02:02,800 --> 00:02:10,600 ‫Longyear very useful for social media because I don't know or very useful for Hey Tech this year. 28 00:02:10,810 --> 00:02:14,840 ‫It's easy to remember than you are this big, right? 29 00:02:15,940 --> 00:02:16,330 ‫All right. 30 00:02:16,810 --> 00:02:24,190 ‫That being said, the first design that comes to my mind and it's no longer it's not it's not it's not 31 00:02:24,190 --> 00:02:25,300 ‫perfect by any means. 32 00:02:25,660 --> 00:02:29,290 ‫But the first design is I'm going to have a database here, OK? 33 00:02:29,560 --> 00:02:36,040 ‫And an excuse me, guys, as I navigate this thing, because this is the first time I do this. 34 00:02:36,040 --> 00:02:37,660 ‫But here there's a database. 35 00:02:38,680 --> 00:02:44,020 ‫I actually like the other databases that I bought for you guys. 36 00:02:44,020 --> 00:02:45,880 ‫A special thing here. 37 00:02:45,940 --> 00:02:46,320 ‫All right. 38 00:02:46,330 --> 00:02:48,280 ‫So we have a database, guys. 39 00:02:48,280 --> 00:02:48,610 ‫All right. 40 00:02:48,880 --> 00:02:50,200 ‫This is a beautiful database. 41 00:02:50,410 --> 00:02:52,420 ‫And all right, we have a database. 42 00:02:52,430 --> 00:02:54,940 ‫How about we add a computer, guys? 43 00:02:55,360 --> 00:02:55,690 ‫Right. 44 00:02:57,010 --> 00:02:58,720 ‫As I add another computer. 45 00:03:00,570 --> 00:03:01,920 ‫As the client tried. 46 00:03:02,900 --> 00:03:10,730 ‫And I don't know if this sounds good, looks good, so we have a database, we have a client, but since 47 00:03:10,730 --> 00:03:15,260 ‫this is kind of a Web application, we kind of need also a Web server. 48 00:03:15,260 --> 00:03:15,680 ‫Correct. 49 00:03:16,320 --> 00:03:22,010 ‫But we had a Web server, Web site, Web server. 50 00:03:23,510 --> 00:03:25,130 ‫They go, that looks like a Web server. 51 00:03:26,150 --> 00:03:29,540 ‫So that's where our application logic will lie. 52 00:03:29,840 --> 00:03:34,940 ‫This is my database and this was the declined that request a U. 53 00:03:34,940 --> 00:03:36,710 ‫RL to be shortened. 54 00:03:37,010 --> 00:03:45,040 ‫And the same logic that reversed a short you are back to a long one will live under the same code base, 55 00:03:45,050 --> 00:03:45,370 ‫right? 56 00:03:45,980 --> 00:03:48,620 ‫I think so, unless you guys disagree. 57 00:03:50,150 --> 00:03:50,480 ‫All right. 58 00:03:50,480 --> 00:03:51,740 ‫So this is a database. 59 00:03:51,740 --> 00:03:55,010 ‫And here's the first design that comes to my mind. 60 00:03:55,130 --> 00:04:04,280 ‫I am going to use a table like this in the database and it's going to be like an ID and there will be 61 00:04:04,280 --> 00:04:06,080 ‫another field called the URL. 62 00:04:06,530 --> 00:04:08,210 ‫And pretty much that's it. 63 00:04:08,930 --> 00:04:09,670 ‫That's it. 64 00:04:10,130 --> 00:04:11,990 ‫You are the longer you will come here. 65 00:04:12,170 --> 00:04:12,490 ‫Right. 66 00:04:12,650 --> 00:04:15,890 ‫That's the longer you're out all night long. 67 00:04:16,130 --> 00:04:23,330 ‫You URL excuse my handwriting here guys, but I'm still working on the sketching pad thing and this 68 00:04:23,330 --> 00:04:26,420 ‫guy is going to be a serial. 69 00:04:28,640 --> 00:04:34,430 ‫Field and polls, because there is a cereal field, and as soon as it feels like every time you add 70 00:04:34,430 --> 00:04:38,690 ‫a row and you row here, this is will be auto generated for you. 71 00:04:38,730 --> 00:04:40,340 ‫There's going to be one, right. 72 00:04:40,550 --> 00:04:42,260 ‫Or two and three and so on. 73 00:04:42,440 --> 00:04:44,360 ‫And then it's going to be a 64 bit. 74 00:04:44,390 --> 00:04:50,210 ‫So the maximum number we're going to get is sixty four minus one, which is a huge number. 75 00:04:50,220 --> 00:04:52,210 ‫How about we actually check how big is this number. 76 00:04:52,430 --> 00:04:54,300 ‫That's the biggest sixty four Bettinger. 77 00:04:54,320 --> 00:04:54,860 ‫Look at this. 78 00:04:54,860 --> 00:04:57,060 ‫It's really, really huge right. 79 00:04:57,080 --> 00:04:58,520 ‫It's around 20 digits. 80 00:04:59,240 --> 00:04:59,570 ‫Right. 81 00:04:59,570 --> 00:05:01,700 ‫20 characters if you will. 82 00:05:01,880 --> 00:05:04,360 ‫So obviously it's a huge number. 83 00:05:04,400 --> 00:05:04,820 ‫Right. 84 00:05:05,060 --> 00:05:09,320 ‫So this is how many rows I can have in my table. 85 00:05:09,710 --> 00:05:11,910 ‫But it is big that you can store this much. 86 00:05:12,050 --> 00:05:12,850 ‫All right. 87 00:05:13,460 --> 00:05:20,740 ‫So what will happen here is if you made a request, right, you will just specify that you are. 88 00:05:20,940 --> 00:05:21,980 ‫And I think that's enough. 89 00:05:22,010 --> 00:05:23,360 ‫We'll go we're going to walk through that. 90 00:05:23,510 --> 00:05:23,790 ‫Right. 91 00:05:23,990 --> 00:05:29,900 ‫So let's say I'm going to shorten a big you, Auriol, and you're going to start writing this here and 92 00:05:29,900 --> 00:05:30,800 ‫you're going to get a number. 93 00:05:31,160 --> 00:05:31,530 ‫Right. 94 00:05:31,910 --> 00:05:33,790 ‫So let's walk through an example. 95 00:05:33,800 --> 00:05:34,280 ‫How about that? 96 00:05:35,000 --> 00:05:36,830 ‫I might make a post request here. 97 00:05:37,130 --> 00:05:37,480 ‫Right. 98 00:05:39,660 --> 00:05:47,460 ‫Both requests slash and you're going to give you all right that that both requests will be received 99 00:05:47,460 --> 00:05:51,950 ‫by the server and the server will establish a TCP connection to the database. 100 00:05:51,960 --> 00:05:52,360 ‫Right. 101 00:05:52,380 --> 00:05:55,690 ‫I'm assuming then he was my school or the Postgres. 102 00:05:56,280 --> 00:05:59,620 ‫I'm I'm going with relational for consistency reasons here. 103 00:05:59,940 --> 00:06:05,760 ‫So now I'm going to establish a connection here and I'm going to write right to this is an insert statement 104 00:06:06,180 --> 00:06:06,750 ‫immediately. 105 00:06:06,760 --> 00:06:12,360 ‫I'm going to do an insert sequel's insert and I'm going to specify the URL and what the database will 106 00:06:12,360 --> 00:06:20,640 ‫give me back is a number, either one to give me which sequence and that I'll take that to sequence 107 00:06:20,640 --> 00:06:22,220 ‫it and return it back to the client. 108 00:06:22,230 --> 00:06:30,810 ‫So the order will be slash one, slash two that that is slash 17 and so on. 109 00:06:31,450 --> 00:06:31,860 ‫Right. 110 00:06:32,940 --> 00:06:35,480 ‫So that's the original design. 111 00:06:36,180 --> 00:06:36,450 ‫Right. 112 00:06:36,660 --> 00:06:40,980 ‫Let's go through that and we're going to talk about the pros and cons of this design, obviously, guys. 113 00:06:40,980 --> 00:06:43,950 ‫But that's that's one design, right? 114 00:06:44,580 --> 00:06:47,910 ‫If you don't really care about having custom URLs that work. 115 00:06:47,910 --> 00:06:48,230 ‫Right. 116 00:06:48,600 --> 00:06:52,320 ‫But let's say I break down the database design a little bit here. 117 00:06:52,890 --> 00:07:01,070 ‫Since this is a database post or a relational database, I want this to have an index entry into this 118 00:07:01,080 --> 00:07:01,320 ‫skull. 119 00:07:01,390 --> 00:07:02,280 ‫Yeah, I can change this. 120 00:07:02,430 --> 00:07:02,910 ‫How about that? 121 00:07:03,120 --> 00:07:04,590 ‫I'm going to have this as an index. 122 00:07:06,630 --> 00:07:07,860 ‫I need an index on this, right? 123 00:07:07,890 --> 00:07:09,740 ‫Probably a primary key. 124 00:07:09,810 --> 00:07:11,970 ‫That's that's going to be my primary key. 125 00:07:12,300 --> 00:07:12,650 ‫Right. 126 00:07:12,900 --> 00:07:14,250 ‫And going to be by default. 127 00:07:14,430 --> 00:07:22,170 ‫Primary is going to have an index or look up on this guy is going to be extremely fast because it's 128 00:07:22,170 --> 00:07:22,760 ‫an integer. 129 00:07:23,190 --> 00:07:24,500 ‫It's only 64 bit. 130 00:07:24,720 --> 00:07:27,480 ‫So the index size is so tiny. 131 00:07:27,630 --> 00:07:28,130 ‫Right. 132 00:07:28,620 --> 00:07:33,840 ‫Plus, we don't really make a good request example showing you get a request. 133 00:07:33,840 --> 00:07:36,460 ‫So let's just walk through a get request example. 134 00:07:36,750 --> 00:07:41,640 ‫So the client will make a request, says, hey, get. 135 00:07:43,630 --> 00:07:44,570 ‫Seven, right? 136 00:07:44,770 --> 00:07:48,600 ‫I want you all to watch them and it's going to be the domain slash seven, right? 137 00:07:48,910 --> 00:07:54,790 ‫And that server will receive that is going to make a query and this time is going to be select right 138 00:07:55,330 --> 00:07:56,350 ‫to the database. 139 00:07:56,560 --> 00:07:59,920 ‫And the database will select where I.D. is equal seven. 140 00:08:00,870 --> 00:08:06,780 ‫My God, how fast is this, because this is an indexed column and it's an integer, so the index is 141 00:08:06,780 --> 00:08:07,590 ‫so tiny. 142 00:08:07,840 --> 00:08:08,210 ‫All right. 143 00:08:08,430 --> 00:08:13,110 ‫So the query will be extremely fast and we're going to get back the results. 144 00:08:13,380 --> 00:08:14,570 ‫OK, this is the URL. 145 00:08:14,940 --> 00:08:22,210 ‫The the the the the and the server will return that and return the oil to the user suite. 146 00:08:22,790 --> 00:08:24,230 ‫So that's that seems OK. 147 00:08:24,270 --> 00:08:24,950 ‫That seems OK. 148 00:08:25,020 --> 00:08:25,350 ‫Right. 149 00:08:25,410 --> 00:08:29,640 ‫So the only index technically that we need is just this. 150 00:08:30,330 --> 00:08:33,910 ‫We don't need another index and extremely fast. 151 00:08:34,380 --> 00:08:36,830 ‫So let's start to scale this up a little bit. 152 00:08:36,870 --> 00:08:39,540 ‫I am writing I'm posting a lot of URLs. 153 00:08:39,540 --> 00:08:39,890 ‫Right. 154 00:08:39,930 --> 00:08:42,570 ‫And I'm getting this incremental yds rame. 155 00:08:42,810 --> 00:08:45,720 ‫So I'm going to get up to like a million or two million. 156 00:08:45,720 --> 00:08:51,180 ‫Three million that does this database can handle definitely can handle databases, can handle three, 157 00:08:51,180 --> 00:08:53,130 ‫four billion records easily. 158 00:08:53,280 --> 00:08:55,230 ‫And writing will. 159 00:08:55,620 --> 00:08:58,320 ‫The writing becomes slower if I have a billion rows here. 160 00:08:58,740 --> 00:08:59,590 ‫Absolutely not. 161 00:09:00,630 --> 00:09:06,330 ‫Well, we're going to talk about that because writing here, I'm not querying to write and I am guaranteed 162 00:09:06,330 --> 00:09:08,730 ‫that this idea is always going to be unique. 163 00:09:08,940 --> 00:09:09,230 ‫Right. 164 00:09:09,270 --> 00:09:12,200 ‫I'm not quitting the database to check if it exists or not. 165 00:09:12,450 --> 00:09:14,970 ‫The database I'm only writing. 166 00:09:14,970 --> 00:09:17,400 ‫So writing is absolutely fast. 167 00:09:17,610 --> 00:09:21,270 ‫And every time I write something, I'm going to always get a new idea. 168 00:09:21,810 --> 00:09:22,230 ‫Right. 169 00:09:22,260 --> 00:09:25,890 ‫So I don't really need to query how awesome is this. 170 00:09:25,980 --> 00:09:26,340 ‫Right. 171 00:09:26,890 --> 00:09:32,970 ‫Immediately get an idea every time, whether it's a billion row, whether it's three billion or trillion 172 00:09:33,210 --> 00:09:36,600 ‫rights is going to be fast because right at the end. 173 00:09:37,140 --> 00:09:45,720 ‫Now, if you want to get a little bit technical here, this database, if it's a battery right based 174 00:09:45,720 --> 00:09:51,930 ‫database like the engine, the storage engine is arbitrary, then rights are going to get slower and 175 00:09:51,930 --> 00:09:56,220 ‫slower the larger you get because this index is arbitrary index. 176 00:09:56,400 --> 00:10:00,660 ‫And as you guys know, with B 3s, we try to balance those trees. 177 00:10:00,660 --> 00:10:00,990 ‫Right. 178 00:10:00,990 --> 00:10:02,810 ‫And I'm going to make a video about butcheries maybe. 179 00:10:03,090 --> 00:10:04,470 ‫And as I start writing right. 180 00:10:04,470 --> 00:10:11,730 ‫And running those, Beatriz's was going to be get slower to rebalance because we need to reshuffle the 181 00:10:11,730 --> 00:10:14,640 ‫trees and move the data structures around. 182 00:10:14,650 --> 00:10:19,010 ‫So Ryan is going to be slower the more data you have. 183 00:10:19,410 --> 00:10:23,290 ‫But if you're using an entry, right. 184 00:10:23,430 --> 00:10:25,820 ‫Like Cassandra, Cassandra is not an author. 185 00:10:25,860 --> 00:10:27,940 ‫Well, let's let's take north equal out of the equation. 186 00:10:28,080 --> 00:10:35,100 ‫Let's say you're using rocks, DB and mythical persona, for example, rocks, DB or my rocks. 187 00:10:35,100 --> 00:10:35,410 ‫Right. 188 00:10:35,670 --> 00:10:42,780 ‫So my skull can be configured with an LSM engine and element in this case is going to be the best because 189 00:10:42,780 --> 00:10:44,220 ‫writing is going to be so fast. 190 00:10:44,910 --> 00:10:50,850 ‫Now let's jump into I think we talked about the you are we talk about the table design, we talk about 191 00:10:50,850 --> 00:10:54,380 ‫the querying here and looks good. 192 00:10:54,510 --> 00:10:56,940 ‫This isn't I'm not interested in any caching or anything. 193 00:10:56,940 --> 00:11:00,720 ‫Guys, you can use caching, but let's just make it simple. 194 00:11:01,410 --> 00:11:04,870 ‫This code is going to be so short, right. 195 00:11:05,100 --> 00:11:09,180 ‫That the code to generate that and I'm going to show you the code as well. 196 00:11:09,720 --> 00:11:14,580 ‫Hopefully, I don't know if I'm going to do go through the code was the code is really easy to write 197 00:11:14,580 --> 00:11:14,760 ‫here. 198 00:11:14,760 --> 00:11:15,090 ‫Right. 199 00:11:15,420 --> 00:11:17,340 ‫So that's the first design. 200 00:11:17,730 --> 00:11:18,610 ‫Is this perfect? 201 00:11:18,840 --> 00:11:19,860 ‫Absolutely not. 202 00:11:19,860 --> 00:11:28,260 ‫Because Hosain, I don't like this, but slash seven is as large as larger because it's very predictable. 203 00:11:28,290 --> 00:11:28,620 ‫Right. 204 00:11:28,920 --> 00:11:33,840 ‫That predictable design is going to you can predict the next you are very simply. 205 00:11:34,200 --> 00:11:36,810 ‫And that's not a good idea for hackers. 206 00:11:36,810 --> 00:11:43,530 ‫Like if you if you give don't ever get about attacker the the clue. 207 00:11:44,730 --> 00:11:51,690 ‫Of this incremental, predictable ideas, because they can do bad things with this, right, but if 208 00:11:51,690 --> 00:11:57,150 ‫you don't really care, right, and they use those like these these stories are public anyway. 209 00:11:57,630 --> 00:11:58,050 ‫Right. 210 00:11:59,480 --> 00:12:04,760 ‫That's OK, but what they can do is essentially they can scan your database, right, because they can 211 00:12:04,760 --> 00:12:12,170 ‫just write a code to loop through all the ideas from one to one billion and they can retrieve all the 212 00:12:12,170 --> 00:12:12,980 ‫URLs. 213 00:12:13,280 --> 00:12:15,620 ‫I don't know why they're going to do that, but they can. 214 00:12:16,400 --> 00:12:19,370 ‫So the predictability is July four attack is back. 215 00:12:19,530 --> 00:12:21,110 ‫So some people don't like this. 216 00:12:21,600 --> 00:12:27,170 ‫I am absolutely fine with it sometimes, especially with the benefits that gives us like this is give 217 00:12:27,170 --> 00:12:31,180 ‫us extreme Goodreads and extreme good rights as well. 218 00:12:31,190 --> 00:12:38,100 ‫Right reads are good and writes the are good as well. 219 00:12:38,840 --> 00:12:40,240 ‫Isn't that fantastic. 220 00:12:40,430 --> 00:12:40,820 ‫Right. 221 00:12:41,860 --> 00:12:43,570 ‫Let's change the color back to what? 222 00:12:44,080 --> 00:12:46,100 ‫All right, so that's why we wanted to do. 223 00:12:46,510 --> 00:12:47,480 ‫Isn't that awesome, guys? 224 00:12:47,670 --> 00:12:51,360 ‫So that's the first design that numbers design get. 225 00:12:52,360 --> 00:12:58,720 ‫The pros, we talk about pros very fast, write and read, but the cons is the predictability, right? 226 00:12:59,020 --> 00:13:02,950 ‫And also that no customer Yoro there is no customer your own this stuff. 227 00:13:03,880 --> 00:13:10,630 ‫There's no ideas like, oh, give me I want you all to say, oh, this is a Kindle, Amazon, whatever 228 00:13:11,170 --> 00:13:11,470 ‫this is. 229 00:13:12,010 --> 00:13:14,040 ‫Amazon is the Amazon one, right? 230 00:13:14,140 --> 00:13:17,950 ‫Oh, this is my presentation for the executives. 231 00:13:18,730 --> 00:13:24,040 ‫You're going to do custom murals if you don't want to do that, if you want to support you, all this 232 00:13:24,040 --> 00:13:25,490 ‫design is yours, right? 233 00:13:25,750 --> 00:13:28,330 ‫So how about we jump in to another design? 234 00:13:28,420 --> 00:13:31,820 ‫Let's clear out this mess guy last year. 235 00:13:31,900 --> 00:13:33,190 ‫See, how about that? 236 00:13:33,220 --> 00:13:34,410 ‫We're clean, guys. 237 00:13:34,420 --> 00:13:34,900 ‫We're clean. 238 00:13:34,900 --> 00:13:35,470 ‫We're back. 239 00:13:36,490 --> 00:13:36,910 ‫All right. 240 00:13:36,910 --> 00:13:38,050 ‫So design. 241 00:13:38,380 --> 00:13:39,250 ‫No. 242 00:13:40,710 --> 00:13:44,330 ‫Two, which is what what are we designing here? 243 00:13:44,730 --> 00:13:49,140 ‫We are designing a system to support custom murals in this case. 244 00:13:50,760 --> 00:13:58,500 ‫Right, and and also, we don't want we don't like this, you are cells that start with numbers because 245 00:13:58,500 --> 00:14:03,180 ‫I don't want to give the attackers ideas of that predictability. 246 00:14:03,180 --> 00:14:03,490 ‫Right. 247 00:14:03,900 --> 00:14:07,410 ‫But they have original design is good for like automated Twitter. 248 00:14:07,420 --> 00:14:08,310 ‫You are of that. 249 00:14:08,940 --> 00:14:11,490 ‫The only system will also generate these. 250 00:14:11,490 --> 00:14:19,950 ‫You are ill and store them in that way and the user will never actually see them short. 251 00:14:19,980 --> 00:14:22,050 ‫They are always going to see them long. 252 00:14:22,950 --> 00:14:26,640 ‫So you can use that original design if the user is not going to see those. 253 00:14:26,980 --> 00:14:27,300 ‫Right. 254 00:14:27,600 --> 00:14:29,640 ‫But it's absolutely beneficial. 255 00:14:29,740 --> 00:14:31,020 ‫Right, Sister? 256 00:14:31,020 --> 00:14:33,300 ‫Number two is I want to support customer. 257 00:14:33,540 --> 00:14:42,540 ‫So that means if I want to post right on a post here, I make a post request and then slash the zero. 258 00:14:43,920 --> 00:14:47,960 ‫And then I want to also specify the customer Yooralla look. 259 00:14:48,500 --> 00:14:54,930 ‫So yeah, I want to specify the customer and the customer equal whatever ABC. 260 00:14:55,830 --> 00:14:56,140 ‫Right. 261 00:14:56,340 --> 00:15:02,370 ‫So I want to specify how the you are ill will be stored in short form. 262 00:15:02,520 --> 00:15:02,830 ‫Right. 263 00:15:03,180 --> 00:15:04,300 ‫So this is a post request. 264 00:15:04,320 --> 00:15:07,310 ‫Well, how are we going to do this? 265 00:15:07,890 --> 00:15:08,140 ‫All right. 266 00:15:08,250 --> 00:15:09,720 ‫Let's think of the table design. 267 00:15:09,720 --> 00:15:11,180 ‫How are we going to store this thing? 268 00:15:11,190 --> 00:15:18,480 ‫Well, in this case, I still need the oil, the actual long URL, and there is no escape. 269 00:15:18,690 --> 00:15:20,870 ‫We need the short euro as euro. 270 00:15:21,120 --> 00:15:21,500 ‫Right. 271 00:15:21,780 --> 00:15:28,680 ‫That's how is going to look like, OK, and I'm not sure we're going to need a prime primary queue will 272 00:15:28,680 --> 00:15:29,280 ‫come to that. 273 00:15:29,280 --> 00:15:33,300 ‫But these are the two columns in this case, right? 274 00:15:34,260 --> 00:15:41,070 ‫So now if I come in with a you are ill and I want to post I mean, I want to write, I want to generally 275 00:15:41,070 --> 00:15:44,760 ‫take that you are a long YORO and make it into a short URL. 276 00:15:44,790 --> 00:15:45,940 ‫So what are you going to do? 277 00:15:46,050 --> 00:15:47,610 ‫So many ideas. 278 00:15:47,730 --> 00:15:57,210 ‫The first that comes when I decide to hash it right and generate know 256 byte or which is like an equal 279 00:15:57,210 --> 00:16:00,730 ‫to 32 by Trie, which is usually or character. 280 00:16:00,750 --> 00:16:01,040 ‫Right. 281 00:16:01,260 --> 00:16:06,300 ‫And then take for example, the first eight characters, if you want just an eight fixed eight byte 282 00:16:06,300 --> 00:16:09,600 ‫characters and you can do a base64. 283 00:16:10,050 --> 00:16:10,560 ‫Right. 284 00:16:10,860 --> 00:16:12,990 ‫So they look like these YouTube URLs. 285 00:16:12,990 --> 00:16:13,320 ‫Right. 286 00:16:13,380 --> 00:16:14,970 ‫Which is like let me show you. 287 00:16:15,390 --> 00:16:18,410 ‫So this is how best 64 yards look like guys, right? 288 00:16:18,540 --> 00:16:25,890 ‫It's characters from A lowercase to Z lowercase from a capital to Z capital, and then all the numbers 289 00:16:25,890 --> 00:16:27,860 ‫and plus signs and all that garbage. 290 00:16:28,230 --> 00:16:35,330 ‫So that's how base64 and you only use this much, but it can serve them forever. 291 00:16:35,730 --> 00:16:38,120 ‫Really it can give them a lot of characters. 292 00:16:38,130 --> 00:16:38,460 ‫Right. 293 00:16:38,760 --> 00:16:39,240 ‫So yeah. 294 00:16:39,630 --> 00:16:42,750 ‫Let's just enjoy and have fun guys doing this stuff. 295 00:16:43,050 --> 00:16:45,720 ‫So are we going to start eight characters. 296 00:16:45,720 --> 00:16:45,970 ‫Right. 297 00:16:45,990 --> 00:16:50,840 ‫So eight bytes take the first eight by then make them into base64. 298 00:16:50,850 --> 00:16:53,000 ‫So that's the character. 299 00:16:53,010 --> 00:16:54,480 ‫So we're starting a. 300 00:16:55,760 --> 00:16:58,000 ‫Technically, eight by three, right? 301 00:16:58,990 --> 00:17:06,940 ‫And just like A, B, C, whatever, and this is the long euro gap, and technically what I want to 302 00:17:06,940 --> 00:17:13,360 ‫do here is I'm going to make this into last year was another color. 303 00:17:14,230 --> 00:17:16,810 ‫I'm going to make this into a primary key. 304 00:17:17,080 --> 00:17:17,550 ‫Right. 305 00:17:17,560 --> 00:17:27,730 ‫So I want to prevent multiple same orals from getting Cleide because now and the previous design, you 306 00:17:27,730 --> 00:17:30,060 ‫don't have collision, you will never have collision. 307 00:17:30,070 --> 00:17:31,570 ‫The problem of collision doesn't exist. 308 00:17:31,840 --> 00:17:32,050 ‫Right. 309 00:17:32,500 --> 00:17:39,490 ‫But here now you have the problem of collision because now you're showing hashing and you're getting 310 00:17:39,700 --> 00:17:45,160 ‫taking a huge string and making the smaller string, which is the idea of collision always exists. 311 00:17:45,340 --> 00:17:45,760 ‫So. 312 00:17:47,010 --> 00:17:48,510 ‫Two ways of solving this problem. 313 00:17:49,500 --> 00:17:58,260 ‫OK, take the post request, do this operation, give that eight characters and attempt to immediately 314 00:17:58,260 --> 00:17:59,790 ‫insert in the database. 315 00:17:59,820 --> 00:18:04,380 ‫Just insert, OK, don't query because it's expensive. 316 00:18:05,250 --> 00:18:07,950 ‫You insert and the database will take care of this. 317 00:18:08,190 --> 00:18:12,660 ‫If the insult was successful, you're going to get a nice short URL, right? 318 00:18:14,400 --> 00:18:18,240 ‫We're going to get that, obviously, you know, the shortfall in this case, unlike that first design, 319 00:18:18,240 --> 00:18:25,890 ‫which we only go in the number, and then you will get a return back the oil for you if that failed. 320 00:18:26,250 --> 00:18:26,610 ‫Right. 321 00:18:26,610 --> 00:18:27,510 ‫Because it can fail. 322 00:18:27,510 --> 00:18:27,670 ‫Right. 323 00:18:27,670 --> 00:18:36,810 ‫The insects can fail because of the duplicate Primerica, then the observer here is responsible of regenerating 324 00:18:36,810 --> 00:18:38,160 ‫a brand new one. 325 00:18:38,190 --> 00:18:40,710 ‫And how do you knew that, guys? 326 00:18:41,190 --> 00:18:41,730 ‫Right. 327 00:18:42,000 --> 00:18:43,240 ‫How do you generate a new one? 328 00:18:43,260 --> 00:18:50,340 ‫I just use the oil and unshowered and took the base64 and I'm going if I regenerate it, I'm going to 329 00:18:50,340 --> 00:18:51,440 ‫get the same one. 330 00:18:52,140 --> 00:18:54,600 ‫So you need the idea of salting here, right? 331 00:18:54,690 --> 00:18:56,090 ‫So that's one way of solving it. 332 00:18:56,400 --> 00:18:57,990 ‫So you generate a random so-called. 333 00:18:58,920 --> 00:19:06,500 ‫And inserted to the shore and then generate a brand new base64, take the first eight characters and 334 00:19:06,510 --> 00:19:13,960 ‫write it down, but the moment you do that, you really do you really need to store the salt. 335 00:19:14,070 --> 00:19:15,690 ‫I'm not sure we'll think about it. 336 00:19:16,320 --> 00:19:19,500 ‫So I didn't really think all of this through. 337 00:19:19,500 --> 00:19:21,900 ‫And I'm prepared to best design for you. 338 00:19:21,930 --> 00:19:27,920 ‫I'm just walking through your shoes and doing it as if it's the first time. 339 00:19:27,920 --> 00:19:30,480 ‫And I wanted to explore everything. 340 00:19:30,670 --> 00:19:32,070 ‫That's the fun of this. 341 00:19:32,220 --> 00:19:36,660 ‫Your shortener is or any system designed as a fun activity. 342 00:19:36,660 --> 00:19:37,860 ‫I want you to have fun. 343 00:19:38,460 --> 00:19:42,370 ‫So let's say I'm not going to store the salt because do we really need to. 344 00:19:42,390 --> 00:19:42,950 ‫I'm not sure. 345 00:19:42,960 --> 00:19:43,220 ‫Right. 346 00:19:43,530 --> 00:19:49,230 ‫So I'm going to store it and then, yeah, we now have a brand new euro, short euro, and then I'm 347 00:19:49,230 --> 00:19:51,910 ‫now returning that short euro to the user. 348 00:19:52,410 --> 00:20:00,270 ‫So there are there could be let's change the color a little bit here and to green and there could be 349 00:20:00,270 --> 00:20:01,950 ‫some sort of a feedback loop here. 350 00:20:02,400 --> 00:20:02,700 ‫Right. 351 00:20:02,970 --> 00:20:06,180 ‫Going back and forth, back and forth, back and forth, because I'll try. 352 00:20:06,660 --> 00:20:08,240 ‫Got a collision because it failed. 353 00:20:08,250 --> 00:20:09,090 ‫I'm going to try again. 354 00:20:09,330 --> 00:20:09,780 ‫Failed. 355 00:20:09,780 --> 00:20:10,910 ‫I'm going to try again fail. 356 00:20:10,920 --> 00:20:11,640 ‫I'm going to try again. 357 00:20:11,640 --> 00:20:11,970 ‫Failed. 358 00:20:12,150 --> 00:20:13,150 ‫OK, you got the idea. 359 00:20:13,860 --> 00:20:18,260 ‫So there could be a failure here, but you're relying on the database to give you the failure. 360 00:20:18,310 --> 00:20:22,080 ‫It's very fast because there's a primary key and it's obviously indexed. 361 00:20:22,080 --> 00:20:22,340 ‫Right. 362 00:20:23,100 --> 00:20:25,800 ‫So you can you can have this loop of failure. 363 00:20:25,800 --> 00:20:33,600 ‫And this could take a long time to resolve if you have if you have a bad, solid algorithm, essentially. 364 00:20:33,960 --> 00:20:35,070 ‫But that's another idea. 365 00:20:35,250 --> 00:20:36,980 ‫And now you can just take that. 366 00:20:37,350 --> 00:20:39,600 ‫You can also take that to you. 367 00:20:39,610 --> 00:20:40,830 ‫All right. 368 00:20:42,030 --> 00:20:49,030 ‫So that's the idea of case of I do not want I want a random short URL. 369 00:20:49,260 --> 00:20:55,710 ‫But if you want to take the users and put your URL and they use this as a euro, that's easy, right? 370 00:20:55,860 --> 00:20:56,970 ‫You just inserted it. 371 00:20:57,210 --> 00:20:58,500 ‫You try to attempt to answer it. 372 00:20:58,500 --> 00:21:00,210 ‫If it exists, you're going to get an error. 373 00:21:00,210 --> 00:21:05,010 ‫And you in that particular case, you need to return the error. 374 00:21:06,590 --> 00:21:14,870 ‫To the user, right, because this user, this you supplied a custom, Yoro, and that is already exist. 375 00:21:15,260 --> 00:21:21,950 ‫But in case if the user did not specify that you don't want to add or write so you could just became 376 00:21:21,950 --> 00:21:27,970 ‫more complicated just because you want to support this custom YORO thingy, is it worth it? 377 00:21:28,430 --> 00:21:29,750 ‫Maybe, yes. 378 00:21:29,970 --> 00:21:33,320 ‫Saying I'm sorry, but I need to do this. 379 00:21:33,320 --> 00:21:34,250 ‫I need to support custom. 380 00:21:34,260 --> 00:21:37,280 ‫You also you have to pay the price of this loop. 381 00:21:37,460 --> 00:21:41,690 ‫You have to pay the price of this branching of the code or the custom. 382 00:21:41,690 --> 00:21:44,700 ‫You all return on it or else do this right. 383 00:21:45,020 --> 00:21:47,540 ‫So there is like a lot of stuff happening here. 384 00:21:48,590 --> 00:21:52,390 ‫Plus your primary key index is now bigger guys, right? 385 00:21:52,790 --> 00:21:58,190 ‫I mean, nobody cares about storage these days, but how big it really it is. 386 00:21:58,190 --> 00:22:00,080 ‫But now it's a body. 387 00:22:00,080 --> 00:22:02,750 ‫You can do the math, but your index is larger. 388 00:22:02,750 --> 00:22:08,600 ‫Now your right is going to be slower because it's a strength versus it's a bite, for God's sake, versus 389 00:22:08,600 --> 00:22:10,370 ‫64 bit. 390 00:22:10,560 --> 00:22:15,650 ‫Well, the orbit, is it big, but integers versus strings. 391 00:22:15,650 --> 00:22:17,730 ‫Yeah, and this is the same same index. 392 00:22:17,810 --> 00:22:18,920 ‫So I apologize for that. 393 00:22:19,070 --> 00:22:19,940 ‫But yeah. 394 00:22:20,270 --> 00:22:21,830 ‫It's a character versus. 395 00:22:23,270 --> 00:22:24,800 ‫Strength versus just numbers. 396 00:22:25,310 --> 00:22:27,730 ‫But now it's a better design, isn't it? 397 00:22:27,740 --> 00:22:28,090 ‫Right. 398 00:22:28,990 --> 00:22:35,470 ‫I have characters, I have just random Strang's, and instead of just predictable numbers that users 399 00:22:35,470 --> 00:22:39,610 ‫can scan my database, I don't want them to scan my database to get all the URLs right. 400 00:22:39,820 --> 00:22:41,710 ‫So this is obviously better. 401 00:22:41,830 --> 00:22:42,960 ‫What do you guys think? 402 00:22:43,000 --> 00:22:48,370 ‫Let me on the comment section, you might say, hey, the first design is good and the second design 403 00:22:48,370 --> 00:22:51,180 ‫is, yeah, I know what it is. 404 00:22:51,190 --> 00:22:58,210 ‫They know the first design definitely does not work in the second design is better, you might say, 405 00:22:58,300 --> 00:22:59,800 ‫Hosain, both designs suck. 406 00:22:59,940 --> 00:23:01,660 ‫Here is a better way of doing it. 407 00:23:01,660 --> 00:23:04,280 ‫And I would love to hear those. 408 00:23:04,330 --> 00:23:06,260 ‫That's why we are here. 409 00:23:06,520 --> 00:23:09,190 ‫This is a canvas of artist. 410 00:23:09,340 --> 00:23:13,540 ‫You is you is English. 411 00:23:13,690 --> 00:23:15,760 ‫You are an artist. 412 00:23:16,150 --> 00:23:18,080 ‫Paint guys just paint. 413 00:23:18,100 --> 00:23:19,630 ‫Enjoy this process. 414 00:23:19,630 --> 00:23:20,950 ‫Don't take things seriously. 415 00:23:20,960 --> 00:23:23,200 ‫We're all going to die eventually. 416 00:23:23,200 --> 00:23:26,710 ‫So, OK, this is going to get dark. 417 00:23:27,400 --> 00:23:29,740 ‫OK, so that's enjoy this process. 418 00:23:29,740 --> 00:23:30,100 ‫All right. 419 00:23:30,850 --> 00:23:31,840 ‫Definitely faster. 420 00:23:32,260 --> 00:23:33,460 ‫It's a good process. 421 00:23:33,460 --> 00:23:33,880 ‫Good. 422 00:23:33,910 --> 00:23:35,440 ‫So that's the two designs. 423 00:23:36,250 --> 00:23:39,010 ‫And now I'm supporting custom Jarrell's with this. 424 00:23:39,190 --> 00:23:39,610 ‫Right. 425 00:23:39,940 --> 00:23:42,340 ‫And I only needed two fields. 426 00:23:42,610 --> 00:23:44,590 ‫Do you need another fields man. 427 00:23:44,740 --> 00:23:49,270 ‫All right guys, how about we go through a redo operation. 428 00:23:49,360 --> 00:23:50,770 ‫Right since we went right. 429 00:23:50,770 --> 00:23:51,580 ‫Let's do a read. 430 00:23:51,940 --> 00:23:55,030 ‫This thing is painful guys by the way, just deleting, clearing things. 431 00:23:55,030 --> 00:23:59,950 ‫If you have a book, a better way of doing sketching online, let me know in the comments section. 432 00:23:59,950 --> 00:24:00,250 ‫Right. 433 00:24:00,250 --> 00:24:02,230 ‫I'm I'm struggling around here. 434 00:24:02,500 --> 00:24:04,240 ‫So let's write our table again. 435 00:24:04,240 --> 00:24:04,870 ‫We have the. 436 00:24:04,870 --> 00:24:05,830 ‫All right. 437 00:24:06,250 --> 00:24:09,880 ‫We have the short Yahel, which is this eight byte thingy. 438 00:24:10,180 --> 00:24:10,510 ‫Right. 439 00:24:11,290 --> 00:24:13,360 ‫And that's our table. 440 00:24:13,870 --> 00:24:15,700 ‫I think that's the only thing we need to store. 441 00:24:16,240 --> 00:24:17,920 ‫And let's walk through this. 442 00:24:18,100 --> 00:24:20,230 ‫I want to make a get request here. 443 00:24:21,130 --> 00:24:22,060 ‫And this is my Shote. 444 00:24:22,060 --> 00:24:27,190 ‫I'm reading those URLs now and this Myanma, my short, your Amazon. 445 00:24:28,020 --> 00:24:28,420 ‫Right. 446 00:24:29,110 --> 00:24:31,090 ‫And then we take that character. 447 00:24:31,090 --> 00:24:34,180 ‫We take this string and we query the database. 448 00:24:34,180 --> 00:24:34,660 ‫Right. 449 00:24:35,290 --> 00:24:43,210 ‫Let's bless obviously, guys, we need to do as much sanitation as possible to not like because someone 450 00:24:43,210 --> 00:24:47,290 ‫was like Amazon, a second injection. 451 00:24:47,740 --> 00:24:52,750 ‫Well, the McAllen draw table. 452 00:24:54,840 --> 00:25:03,840 ‫You what else they can do that and screw the whole database, so sanitize your input and it's easier 453 00:25:03,840 --> 00:25:04,730 ‫than ever. 454 00:25:05,190 --> 00:25:09,790 ‫Check out my videos on sexual injections and sanitation and all that jazz. 455 00:25:10,530 --> 00:25:17,460 ‫So, yeah, we all to do a select statement here, guys, where the blah, blah, blah equal Amazon. 456 00:25:17,670 --> 00:25:19,950 ‫And then we're going to immediately query that. 457 00:25:20,160 --> 00:25:20,560 ‫Right. 458 00:25:20,610 --> 00:25:23,460 ‫And that's fast because there is an index here, right? 459 00:25:23,550 --> 00:25:24,900 ‫We built an index. 460 00:25:25,200 --> 00:25:30,940 ‫So so now this huge one billion rose is now smaller, but still good. 461 00:25:31,320 --> 00:25:36,540 ‫I mean, people can do sharding and all that stuff, but I really recommend you not to unless your system 462 00:25:36,540 --> 00:25:39,390 ‫is big enough to really need sharding. 463 00:25:39,400 --> 00:25:43,380 ‫And I talked about when to shorten, when not to show or check out the videos there. 464 00:25:44,040 --> 00:25:50,790 ‫But I'm going to query that if I find it, I'm going to return that actual URL, which is this guy. 465 00:25:50,790 --> 00:25:51,170 ‫Right. 466 00:25:51,390 --> 00:25:53,010 ‫And then I'm going to return it to the user. 467 00:25:53,160 --> 00:25:59,280 ‫And by return, I mean literally just do a three or one was three directory one or three or two and 468 00:25:59,280 --> 00:26:01,520 ‫do a location equal that. 469 00:26:01,530 --> 00:26:04,680 ‫So in order to immediately redirect that stuff. 470 00:26:04,680 --> 00:26:04,970 ‫Right. 471 00:26:05,550 --> 00:26:07,740 ‫So maybe another video, I'm going to actually sit down. 472 00:26:07,750 --> 00:26:09,120 ‫I actually do that code for you. 473 00:26:09,450 --> 00:26:11,580 ‫I just want to make the video real short. 474 00:26:12,030 --> 00:26:13,320 ‫I don't want to make the video long. 475 00:26:14,010 --> 00:26:16,390 ‫You all shot the design we give to designs. 476 00:26:16,410 --> 00:26:23,210 ‫And now I want you to just while walking through the scenarios, what else can we do? 477 00:26:23,220 --> 00:26:24,840 ‫Can we use nautical databases? 478 00:26:24,870 --> 00:26:25,520 ‫Definitely. 479 00:26:25,860 --> 00:26:27,240 ‫Can you use caching? 480 00:26:27,240 --> 00:26:33,610 ‫Can you use right is definitely you can do a lot of stuff to optimize this. 481 00:26:33,660 --> 00:26:35,970 ‫So what's the process of this design process? 482 00:26:36,000 --> 00:26:44,730 ‫Well, I have my beautiful custom URLs and I don't no longer have this scanning problem that Korn's 483 00:26:44,730 --> 00:26:47,250 ‫it's 100 percent slower than the first design. 484 00:26:48,000 --> 00:26:48,360 ‫Right. 485 00:26:48,630 --> 00:26:51,990 ‫At least in the writing process. 486 00:26:52,110 --> 00:26:55,380 ‫And you might say, I don't care, Hosain. 487 00:26:55,500 --> 00:26:57,300 ‫I don't care about the writing process. 488 00:26:57,660 --> 00:27:03,690 ‫And you're absolutely right, because writing how often writing happens compared to reads readers is 489 00:27:03,690 --> 00:27:05,600 ‫going to be always more than right. 490 00:27:05,600 --> 00:27:05,900 ‫Right. 491 00:27:06,300 --> 00:27:07,530 ‫So I always think about that. 492 00:27:08,100 --> 00:27:11,960 ‫How many people click on short yardage versus how many people generate shortfalls. 493 00:27:11,970 --> 00:27:12,200 ‫Right. 494 00:27:13,710 --> 00:27:18,150 ‫Unless your Twitter, if you're if you care about reads writes. 495 00:27:18,630 --> 00:27:19,020 ‫Right. 496 00:27:19,200 --> 00:27:19,620 ‫Like. 497 00:27:20,640 --> 00:27:26,670 ‫Like for Twitter, like every time you go to a tweet and put a long you on a Twitter automatically shortens 498 00:27:26,670 --> 00:27:26,850 ‫it. 499 00:27:26,920 --> 00:27:29,780 ‫So and Twitter have a lot of rights. 500 00:27:29,790 --> 00:27:30,150 ‫Right. 501 00:27:30,660 --> 00:27:37,170 ‫So now in this case, you might prefer the first design because you're going to store that in a short 502 00:27:37,170 --> 00:27:40,080 ‫manner and you're going to retrieve it also in a short manner. 503 00:27:40,080 --> 00:27:45,840 ‫But you're going to show the user always the long years, AZO, that doesn't they don't even know the 504 00:27:45,840 --> 00:27:47,390 ‫short you all actually exists. 505 00:27:48,000 --> 00:27:48,360 ‫Right. 506 00:27:49,110 --> 00:27:50,880 ‫So you might you might first design my work. 507 00:27:51,150 --> 00:27:58,440 ‫But if you're building an actual tiny oil custom for the user, bit like this design absolutely works, 508 00:27:58,440 --> 00:27:58,820 ‫right. 509 00:28:00,780 --> 00:28:08,500 ‫And I did talk about scaling persay across the whole ward for this, right. 510 00:28:08,790 --> 00:28:12,050 ‫So let's talk about that a little bit before we in the video. 511 00:28:12,300 --> 00:28:17,280 ‫So if I am if I want to scale this design right, let's talk about this a little bit. 512 00:28:17,460 --> 00:28:18,010 ‫Scaling. 513 00:28:18,180 --> 00:28:18,750 ‫All right. 514 00:28:18,750 --> 00:28:19,590 ‫Scaling. 515 00:28:20,260 --> 00:28:22,800 ‫Let's talk about scaling for both design one and two. 516 00:28:22,830 --> 00:28:23,490 ‫It's the same. 517 00:28:23,490 --> 00:28:24,630 ‫I think there's the same problem. 518 00:28:24,630 --> 00:28:24,990 ‫Right. 519 00:28:25,400 --> 00:28:26,820 ‫So let's talk about the scaling. 520 00:28:26,820 --> 00:28:26,950 ‫Right. 521 00:28:27,000 --> 00:28:34,030 ‫Because that's what the noncyclical people have against the relational databases that they don't scale. 522 00:28:34,050 --> 00:28:36,330 ‫So scaling in this case, what are we going to do, guys? 523 00:28:37,660 --> 00:28:44,290 ‫And we can clear all that garbage, we don't really need it, but here's the thing, we will make one 524 00:28:44,290 --> 00:28:44,890 ‫master. 525 00:28:46,350 --> 00:28:49,620 ‫Database and multiple backup databases. 526 00:28:50,440 --> 00:28:52,930 ‫Right, and that's changed. 527 00:28:52,990 --> 00:28:55,680 ‫Can I change the color on this stuff? 528 00:28:56,310 --> 00:28:57,360 ‫I don't think I can. 529 00:28:57,360 --> 00:28:57,680 ‫Huh? 530 00:29:00,170 --> 00:29:00,650 ‫Never mind. 531 00:29:00,680 --> 00:29:03,640 ‫All right, I can't change that color, but here's the thing, guys. 532 00:29:03,680 --> 00:29:04,850 ‫So this thing is going to be. 533 00:29:06,590 --> 00:29:07,010 ‫The. 534 00:29:08,040 --> 00:29:13,050 ‫Back up and this guy is also going to be a backup. 535 00:29:14,390 --> 00:29:19,360 ‫What does that mean, a backup means it's designed just for reeds, right? 536 00:29:20,320 --> 00:29:21,550 ‫Because that's what do you want to scale? 537 00:29:21,580 --> 00:29:26,610 ‫You want to scale reads, right, and the rights always goes to one single database. 538 00:29:26,890 --> 00:29:29,110 ‫So there's one single database in Central America. 539 00:29:29,140 --> 00:29:30,340 ‫I don't know, North Virginia. 540 00:29:30,490 --> 00:29:30,880 ‫Right. 541 00:29:31,240 --> 00:29:35,110 ‫And there is a process that pushes. 542 00:29:36,170 --> 00:29:43,570 ‫That writes to these reader replicas, and this is called the application, the idea for replication 543 00:29:43,650 --> 00:29:48,200 ‫application, and this is like any relational database supports this by default. 544 00:29:48,800 --> 00:29:53,180 ‫So now you can scale those guys, right? 545 00:29:53,180 --> 00:29:56,120 ‫That Web servers definitely can be scaled. 546 00:29:56,180 --> 00:29:56,560 ‫Right. 547 00:29:57,810 --> 00:30:07,350 ‫You can put it observer here, but another observer right here and you can point read so you can absolutely 548 00:30:08,040 --> 00:30:09,510 ‫point reads. 549 00:30:10,170 --> 00:30:12,100 ‫When I say reads, I get requests, right. 550 00:30:12,750 --> 00:30:16,290 ‫Hey, give me this URL to this point. 551 00:30:16,290 --> 00:30:17,160 ‫Reads to this. 552 00:30:18,790 --> 00:30:22,070 ‫Right, and point post request to the server. 553 00:30:22,300 --> 00:30:24,610 ‫This is the master or whatever, right? 554 00:30:25,120 --> 00:30:27,340 ‫And this is the post requests and post, of course. 555 00:30:27,340 --> 00:30:30,380 ‫I mean, what I mean, actual rights of short periods. 556 00:30:30,400 --> 00:30:30,620 ‫Right. 557 00:30:30,850 --> 00:30:38,500 ‫So you always configure your system to have this wreathes and you configure it to have rights right 558 00:30:38,500 --> 00:30:39,140 ‫here, OK? 559 00:30:39,460 --> 00:30:43,000 ‫So this kind of scale very easily, right? 560 00:30:43,000 --> 00:30:48,030 ‫Because you you remove the reeds and now you associated this only with the rights. 561 00:30:48,040 --> 00:30:48,520 ‫Correct. 562 00:30:48,790 --> 00:30:55,450 ‫So now this guy that all the reeds can go to this server and all the rest can go to the server and you 563 00:30:55,450 --> 00:30:56,910 ‫can do this all day. 564 00:30:56,920 --> 00:30:57,160 ‫Right. 565 00:30:57,180 --> 00:31:04,060 ‫You can do this like if you're in the U.S., you can do this or the West and this guy is the east. 566 00:31:04,060 --> 00:31:04,480 ‫Right. 567 00:31:04,810 --> 00:31:06,510 ‫And reading is going to be fine. 568 00:31:06,520 --> 00:31:06,840 ‫Right. 569 00:31:07,350 --> 00:31:11,680 ‫Only there will be some sort of an eventual consistency even. 570 00:31:11,710 --> 00:31:12,790 ‫Yes, guys. 571 00:31:12,790 --> 00:31:20,800 ‫Eventual consistency can happen in relational databases, not only not equal, but I am guaranteed that 572 00:31:20,890 --> 00:31:22,990 ‫my rights are always consistent here. 573 00:31:23,530 --> 00:31:32,380 ‫But there will be a lag where if I write something right and at the same time I try to read it is going 574 00:31:32,380 --> 00:31:33,070 ‫to be a lag. 575 00:31:33,070 --> 00:31:33,370 ‫Right. 576 00:31:33,580 --> 00:31:38,080 ‫So sometimes you want this guy to always accept reads as well. 577 00:31:38,080 --> 00:31:40,660 ‫If they are, they're coming from the same IP address. 578 00:31:40,660 --> 00:31:44,030 ‫But that's a detail that you can finesse, guys. 579 00:31:44,680 --> 00:31:46,330 ‫So that's a replication idea. 580 00:31:46,960 --> 00:31:49,180 ‫You might say, Hosain, that's impossible. 581 00:31:49,360 --> 00:31:52,300 ‫One database cannot handle all of this stuff. 582 00:31:52,450 --> 00:31:54,600 ‫Well, that's absolutely fine as well. 583 00:31:54,610 --> 00:32:01,540 ‫You can now, if your rights can no longer scale, then you can go play with the idea of sharding, 584 00:32:02,020 --> 00:32:03,840 ‫which we discussed right here. 585 00:32:03,850 --> 00:32:09,690 ‫Go check the video so you can share this database only if you absolutely cannot handle the rights guys. 586 00:32:09,950 --> 00:32:13,720 ‫Again, you got to really be careful when do you want to share it? 587 00:32:13,720 --> 00:32:19,660 ‫Because it's a very complex operation and you can use my Esequiel, you can use the Oracle Oracle so 588 00:32:19,660 --> 00:32:25,690 ‫expensive he can use MySQL, Postgres, all those relational beautiful databases. 589 00:32:25,810 --> 00:32:30,460 ‫You can also use no SQL databases, but. 590 00:32:31,430 --> 00:32:40,610 ‫I don't I do not like the eventual consistency in my no equal databases, especially with rights, that's 591 00:32:40,610 --> 00:32:47,150 ‫just personal opinion because I prefer to have consistent rights, even in a single instance, but that 592 00:32:47,150 --> 00:32:49,030 ‫databases don't even give you that. 593 00:32:49,610 --> 00:32:52,400 ‫No school that doesn't give you that, unfortunately. 594 00:32:52,730 --> 00:32:54,210 ‫No, I think I'll take that back. 595 00:32:54,230 --> 00:32:59,060 ‫So, yeah, you can replicate this with a Mongo TV, right? 596 00:32:59,330 --> 00:33:03,230 ‫With rights, your rights is going to be passed. 597 00:33:04,040 --> 00:33:07,910 ‫But it really depends on how you're storing this information. 598 00:33:07,920 --> 00:33:10,150 ‫The indexing or not equal databases. 599 00:33:10,160 --> 00:33:11,290 ‫I don't know anything about. 600 00:33:11,390 --> 00:33:11,720 ‫No, no. 601 00:33:12,030 --> 00:33:14,600 ‫I know very little, so I cannot. 602 00:33:15,540 --> 00:33:23,250 ‫Possibly tell you to use no sequel database like Mongul, if I don't actually understand the underlining 603 00:33:24,240 --> 00:33:25,440 ‫functionality, right. 604 00:33:25,500 --> 00:33:30,780 ‫I know that not all not equal support indexes, which is something I just don't like. 605 00:33:31,260 --> 00:33:31,620 ‫Right. 606 00:33:31,800 --> 00:33:35,340 ‫If you don't support indexing, that's just a big no for me. 607 00:33:35,340 --> 00:33:35,580 ‫Right. 608 00:33:35,880 --> 00:33:40,110 ‫I need an index so I can quickly query my stuff. 609 00:33:40,110 --> 00:33:40,350 ‫Right. 610 00:33:40,360 --> 00:33:43,380 ‫I need things that are predictable and that's just mean. 611 00:33:43,380 --> 00:33:46,560 ‫Guys, don't let my opinion force you at all, right? 612 00:33:46,890 --> 00:33:49,770 ‫Just I want just wants to understand different thing. 613 00:33:49,800 --> 00:33:51,630 ‫I'm open to different opinions. 614 00:33:51,630 --> 00:33:51,840 ‫Right. 615 00:33:52,140 --> 00:33:53,840 ‫So this is an idea of scaling. 616 00:33:54,150 --> 00:33:55,370 ‫What did I say wrong? 617 00:33:55,410 --> 00:33:56,060 ‫What did I say? 618 00:33:56,070 --> 00:33:56,490 ‫Right. 619 00:33:57,000 --> 00:34:00,090 ‫And by the way, guys, I forgot to mention something very critical here. 620 00:34:00,850 --> 00:34:06,150 ‫There will be a bad ass proxy right here. 621 00:34:06,600 --> 00:34:08,270 ‫Oh, how about that? 622 00:34:08,280 --> 00:34:09,240 ‫We do have a proxy. 623 00:34:10,950 --> 00:34:11,880 ‫Nice. 624 00:34:12,240 --> 00:34:15,390 ‫All of this stuff, we've got to be done with a reverse proxy. 625 00:34:15,510 --> 00:34:15,890 ‫Right. 626 00:34:16,230 --> 00:34:17,910 ‫That could be loaded, balanced. 627 00:34:17,910 --> 00:34:18,270 ‫Right. 628 00:34:18,510 --> 00:34:20,760 ‫To these master services. 629 00:34:20,760 --> 00:34:21,020 ‫Right. 630 00:34:21,300 --> 00:34:25,320 ‫So technically, all of that stuff. 631 00:34:25,320 --> 00:34:25,650 ‫Right. 632 00:34:28,660 --> 00:34:29,050 ‫Right. 633 00:34:29,080 --> 00:34:36,220 ‫All of these requests are going through the proxy first is going through the proxy and the proxy decides, 634 00:34:36,220 --> 00:34:39,350 ‫hey, go here, go here or go here. 635 00:34:39,370 --> 00:34:39,620 ‫Right. 636 00:34:39,620 --> 00:34:40,920 ‫So that's the reverse proxy. 637 00:34:41,020 --> 00:34:41,290 ‫Right. 638 00:34:41,380 --> 00:34:44,110 ‫And you can make unlimited copy of those. 639 00:34:45,420 --> 00:34:53,250 ‫Reverse proxy's, right, that reverse proxy, not acts, doesn't only act like a load balancer, purely 640 00:34:53,260 --> 00:34:58,890 ‫a load balancer and just do the funnel the request to all of them. 641 00:34:59,520 --> 00:35:01,080 ‫No, it actually looks at the data. 642 00:35:01,080 --> 00:35:04,320 ‫So it's probably a layer seven load balancer here. 643 00:35:04,530 --> 00:35:07,260 ‫And it looks at the data says, oh, this is a get request. 644 00:35:07,500 --> 00:35:08,310 ‫I'll take you here. 645 00:35:08,440 --> 00:35:09,600 ‫Well, this is a post request. 646 00:35:10,070 --> 00:35:11,490 ‫Of course, definitely have to be here. 647 00:35:11,640 --> 00:35:11,920 ‫Right. 648 00:35:12,120 --> 00:35:15,540 ‫But get request has to go here and has to go to the server. 649 00:35:16,170 --> 00:35:16,560 ‫Right. 650 00:35:16,680 --> 00:35:22,650 ‫And probably there is a reverse proxy in NE near to each data center like in China, probably going 651 00:35:22,650 --> 00:35:30,390 ‫to have one in Asia and now in Central America and probably in Europe and each one take it to the nearest 652 00:35:30,390 --> 00:35:33,830 ‫server and maybe the master server is going to set in America. 653 00:35:34,200 --> 00:35:34,500 ‫Right. 654 00:35:34,510 --> 00:35:41,730 ‫So, yeah, obviously it's going to be slow for scaling purposes, but maybe you don't really care about 655 00:35:41,730 --> 00:35:42,390 ‫rights much. 656 00:35:42,390 --> 00:35:42,690 ‫Right. 657 00:35:43,020 --> 00:35:44,350 ‫But now comes to the sharding. 658 00:35:44,370 --> 00:35:45,930 ‫Hey, I'm going to share my database. 659 00:35:45,930 --> 00:35:51,120 ‫I'm going to put a shard in Europe so rights are going to be faster. 660 00:35:52,350 --> 00:35:53,910 ‫All about trade off, guys. 661 00:35:54,030 --> 00:35:55,600 ‫It's all about real guys. 662 00:35:55,610 --> 00:35:57,170 ‫I think that's going to stop here. 663 00:35:58,230 --> 00:36:00,120 ‫What do you what do you guys think? 664 00:36:00,540 --> 00:36:01,710 ‫Did you like this episode? 665 00:36:01,860 --> 00:36:05,520 ‫How did you like this interaction of the spend thingee. 666 00:36:05,560 --> 00:36:06,540 ‫Obviously like it. 667 00:36:06,780 --> 00:36:07,770 ‫Give me your opinion. 668 00:36:07,770 --> 00:36:13,980 ‫Give me any critique that you might have in the comments section below, because I love to be better 669 00:36:13,980 --> 00:36:15,330 ‫and do better with you guys. 670 00:36:15,330 --> 00:36:15,570 ‫Right. 671 00:36:15,570 --> 00:36:16,860 ‫And then let's have a discussion. 672 00:36:17,100 --> 00:36:21,390 ‫Why do you guys think is the better way of doing things right? 673 00:36:21,630 --> 00:36:23,430 ‫Everything has a pros and cons. 674 00:36:23,790 --> 00:36:27,600 ‫It's Gumbs comes back to simplicity. 675 00:36:27,810 --> 00:36:39,300 ‫Simplicity, sometimes rules and maybe simple thing can create the best design, really, while having 676 00:36:39,300 --> 00:36:47,370 ‫complexity can having complex design leads to complex implementation, which leads to the things that 677 00:36:47,370 --> 00:36:48,150 ‫we all hate. 678 00:36:48,630 --> 00:36:50,100 ‫Bugs. 679 00:36:50,640 --> 00:36:51,780 ‫We hate bugs, guys. 680 00:36:52,380 --> 00:36:57,390 ‫So simple design needs a simple, elegant implementation with code. 681 00:36:57,540 --> 00:37:04,860 ‫And then once you have a simple implementation, you have a rigid, rigid, you have a solid, bad ass 682 00:37:04,860 --> 00:37:05,550 ‫system. 683 00:37:05,550 --> 00:37:09,510 ‫And you when you have a bad system, you are unstopped, unstoppable. 684 00:37:09,510 --> 00:37:14,000 ‫Guisewite So paint guys sit down and paint. 685 00:37:14,010 --> 00:37:15,150 ‫What do you guys think? 686 00:37:15,150 --> 00:37:20,940 ‫If you know where to start, start somewhere, write something, write anything that comes to your head, 687 00:37:21,430 --> 00:37:21,630 ‫OK? 688 00:37:21,990 --> 00:37:26,520 ‫And that's why when I, when I talk about back in engineering and systems, I need you to understand 689 00:37:26,670 --> 00:37:27,930 ‫how databases work. 690 00:37:28,020 --> 00:37:30,120 ‫I need you to understand how observers work. 691 00:37:30,150 --> 00:37:35,490 ‫So read, read, read, read, read, keep consuming, learn and learn and learn. 692 00:37:35,490 --> 00:37:38,130 ‫Because we are all learning guys here. 693 00:37:38,220 --> 00:37:41,190 ‫I want to know we're not going to stop learning. 694 00:37:42,120 --> 00:37:43,800 ‫Are our guys going to leave you here? 695 00:37:44,310 --> 00:37:44,560 ‫See. 696 00:37:44,580 --> 00:37:45,960 ‫And the next one leave. 697 00:37:45,960 --> 00:37:49,050 ‫I like subscribe and I'm going to see you in the next one. 698 00:37:49,200 --> 00:37:50,010 ‫You guys say awesome.