YouTube2Text

Essential System Design Concepts You Should Know - System Design Tutorial — Transcript

by Caleb Curry · 7,752 words · 1,126 segments · language en · Watch on YouTube

Full transcript

  1. 0:00welcome back to your system design
  2. 0:02Series this video we're actually going
  3. 0:04to talk about some of the most important
  4. 0:05terminology you should be familiar with
  5. 0:08as you start studying the rest of these
  6. 0:09lessons now one of the first things I
  7. 0:11want to talk about is scaling an app
  8. 0:13from just a few users to potentially
  9. 0:15millions of users and we're probably
  10. 0:17going to start that process in the next
  11. 0:19lesson because I want to get some
  12. 0:21foundational stuff of system design out
  13. 0:24in this lesson so this will basically be
  14. 0:25a very brief intro to a bunch of
  15. 0:27different topics and keywords you should
  16. 0:29be amiliar with but you don't need to
  17. 0:31understand them at a very intimate level
  18. 0:33this is really just so when you see
  19. 0:35these words in the future lessons you
  20. 0:37have an idea of what that means and it's
  21. 0:39not completely brand new to you so
  22. 0:41really this is just designed to give you
  23. 0:43that thousand foot view of everything
  24. 0:44we're going to be talking about but you
  25. 0:46don't have to leave this video knowing
  26. 0:48every single word in a lot of depth now
  27. 0:51I just wanted to first show you this
  28. 0:52beautiful system design that my wife
  29. 0:55wrote up here this was for the previous
  30. 0:57video's thumbnail but we're not going to
  31. 0:58leave that up so I'll just do ER that
  32. 1:00real
  33. 1:01quick oh
  34. 1:04snap oh no before we get started I
  35. 1:07wanted to share two Resources with you
  36. 1:09the first is a back-end software
  37. 1:11engineering mind map this is going to
  38. 1:13share with you every technology you
  39. 1:14should know if you want to become a
  40. 1:16backend software engineer the second
  41. 1:18thing is if you need help applying the
  42. 1:19principles that we teach here as well as
  43. 1:21the things on the Mind map then I have a
  44. 1:23mentorship program this is where you can
  45. 1:25get one-on-one help to learn the skills
  46. 1:27to become a software engineer and get a
  47. 1:30high paying software engineering role so
  48. 1:32if that's something you'd be interested
  49. 1:33in I'll have a link for that as well as
  50. 1:35the Mind map down below so the first
  51. 1:37word I want to talk about is distributed
  52. 1:39systems or distributed computing the
  53. 1:42idea of something being distributed is
  54. 1:44running it across multiple
  55. 1:47computers so we'll just say distributed
  56. 1:50computing and these are pretty general
  57. 1:53terms so we're not referring
  58. 1:55specifically to the backend or the
  59. 1:58databases but pretty much anything could
  60. 2:00be ran in a distributed environment we
  61. 2:03will get into some Concepts that apply
  62. 2:06to specific sections of our application
  63. 2:08such as the database level but now we're
  64. 2:10just thinking pretty General anytime we
  65. 2:12want to run an application but it's
  66. 2:15distributed across multiple computers
  67. 2:18we're working with distributed computing
  68. 2:20pretty sure I just Ed the word in the
  69. 2:22definition but the idea is instead of
  70. 2:24running your service on a single
  71. 2:27computer you might run this on multiple
  72. 2:30computers and all three of these in this
  73. 2:32case have to work together to give a
  74. 2:36single result so we have to start
  75. 2:38talking about ways to get multiple
  76. 2:40computers to work together so that we
  77. 2:43end up with just a single result so this
  78. 2:46is going to introduce a lot of
  79. 2:47challenges many of which we'll talk
  80. 2:50about in this series so a lot of the
  81. 2:52next words that we're going to talk
  82. 2:53about build on the idea of distributed
  83. 2:56computing the first one I want to talk
  84. 2:58about is availability so in the
  85. 3:00situation of what we just had where we
  86. 3:02had three computers working
  87. 3:06together this is likely a highly
  88. 3:08available system if one of the computers
  89. 3:11goes out the other two servers will
  90. 3:14compensate taking the load that was
  91. 3:17originally given to this computer so if
  92. 3:20we put a circle around this to basically
  93. 3:23say hey this is one unit and somebody
  94. 3:27makes a request to the service this
  95. 3:30request could go to any of these
  96. 3:32notes and if we structure it to be
  97. 3:36highly available if for some reason this
  98. 3:38node is down the request would not go to
  99. 3:41that node it would just be redirected to
  100. 3:43one of the other nodes so that's the
  101. 3:46idea of availability our goal is to be
  102. 3:49available 24/7 this is impossible so we
  103. 3:52want to get as close as possible to this
  104. 3:54and we'll talk about that now now
  105. 3:56because it is impossible to have a
  106. 3:57service that runs 24/7 guarant aned
  107. 4:00there are different levels of how
  108. 4:02available a service should be and these
  109. 4:04are measured in nines so one nine would
  110. 4:07be 90% of the time which means in one
  111. 4:11year the service could be down 36 and 1
  112. 4:1412 days which is 10% of a year so
  113. 4:1936.5 days of potential downtime now it
  114. 4:22doesn't necessarily mean the service
  115. 4:24always is down 36 days out of the Year
  116. 4:26this will be a worst case scenario if a
  117. 4:28service said that they were guaranteed
  118. 4:30to be up at least 90% of the time then
  119. 4:33we would have two NES which would be 99%
  120. 4:36we're getting a little bit better and
  121. 4:38while that might sound nice like hey
  122. 4:39it's up 99% of the time still pretty bad
  123. 4:42because this would be 3.65
  124. 4:46days so that's 2 9 if you go to Three N
  125. 4:49it would be 99.9 4 9 would be
  126. 4:5399.99 and you can keep adding nines to
  127. 4:56get as close as possible to 100% of the
  128. 4:59time every time you add a nine to your
  129. 5:00service it becomes more difficult but
  130. 5:03low numbers like these are super easy to
  131. 5:05achieve when you start getting to five
  132. 5:07six in a higher number of nines it's
  133. 5:08going to become more challenging but if
  134. 5:10you have a service that goes down almost
  135. 5:124 days once a year that's pretty
  136. 5:14terrible at minimum if you're looking
  137. 5:16for just a ballpark shoot for 49 this
  138. 5:19translates to less than an hour of
  139. 5:22downtime per
  140. 5:25year which for some things that's not
  141. 5:28going to work you know if you're working
  142. 5:30on some medical system or some Financial
  143. 5:32system or military system an hour of
  144. 5:36downtime could be pretty bad but in many
  145. 5:39apps if an app goes down a couple of
  146. 5:42minutes here and there and over the
  147. 5:44course of a year it's less than an hour
  148. 5:46that's pretty good for many apps so this
  149. 5:48would be a benchmark and if you need it
  150. 5:50a little bit more serious then just add
  151. 5:52additional nines and start looking for
  152. 5:54ways to achieve that we'll get into some
  153. 5:56of the ways you can increase the number
  154. 5:57of nines for your services so if you
  155. 6:00don't feel like this is adequate we're
  156. 6:03going to talk about ways you can achieve
  157. 6:05more than that but this is just a
  158. 6:07starting point to summarize that as the
  159. 6:09number of nines go up so does the
  160. 6:12availability which I'm just going to
  161. 6:14write ha for high availability however
  162. 6:17the costs are going to exponentially
  163. 6:19increase as well as the general
  164. 6:22challenge of
  165. 6:23implementing
  166. 6:25the service so more cost and more
  167. 6:28challenge especially something to
  168. 6:30consider if you're hiring developers
  169. 6:32they're going to cost money so not only
  170. 6:36will the services you pay for such as
  171. 6:39database hosting and servers go up in
  172. 6:42cost but the actual skills required to
  173. 6:44implement things and keep everything
  174. 6:46running is going to go up as well and
  175. 6:48that ultimately could come back to cost
  176. 6:50next up we have reliability and this is
  177. 6:53a service's ability to do what it is
  178. 6:55supposed to do so you can imagine you
  179. 6:58have a service that's up
  180. 7:0199.999% of the time but the service is
  181. 7:04nonfunctional or it's doing something
  182. 7:06incorrect such as doing some database
  183. 7:08stuff where data is being lost this
  184. 7:11would be a problem with
  185. 7:14reliability and this is a little bit
  186. 7:16more abstract or hard to measure and
  187. 7:19when you're defining what reliability
  188. 7:21looks like in your app you can define
  189. 7:23those rules so it's not something where
  190. 7:26it's just hey here's a certain number of
  191. 7:28nines it's more abstract you have to
  192. 7:30think about what the application should
  193. 7:32be doing and what success looks like and
  194. 7:34what failure looks like but this is a
  195. 7:36general term to refer to the ability for
  196. 7:38an app to do what it is supposed to do
  197. 7:41so does the app actually work even if
  198. 7:44you have let's
  199. 7:49say 6 9 of uptime you might have z%
  200. 7:54reliability this setup is kind of like
  201. 7:56if you have a friend who's always
  202. 7:58available you can call them text them
  203. 8:00they'll answer always get back and
  204. 8:02they'll help you with anything but when
  205. 8:04you actually need them to come over to
  206. 8:05help you move they don't show up or they
  207. 8:08show up and they're totally useless
  208. 8:10they're always available but they're not
  209. 8:12reliable two different concepts so just
  210. 8:14to kind of get that straighten away in
  211. 8:16your mind availability is about the
  212. 8:17ability to access a service the
  213. 8:19reliability is about is the service
  214. 8:22functional the way it should be
  215. 8:23functioning next big word you should be
  216. 8:25familiar with is consistency so this has
  217. 8:28to do with every everybody seeing the
  218. 8:31same data at the same
  219. 8:34time this is really only going to be a
  220. 8:36concern when you start working in
  221. 8:38distributed systems if you have one
  222. 8:41computer one server that's serving your
  223. 8:43application you are always 100%
  224. 8:46consistent because the definition of
  225. 8:49consistency is everyone sees the same
  226. 8:52data at the same time so everyone here
  227. 8:55is probably going to refer to the
  228. 8:57clients trying to access This Server so
  229. 9:00if you have a web server this could be
  230. 9:03the backend API and people are trying to
  231. 9:05retrieve data through some frontend
  232. 9:08application so we'll get into more of
  233. 9:10all of that architecture throughout this
  234. 9:12series but for our little example here
  235. 9:15we can imagine we have two people and
  236. 9:18they're both on their
  237. 9:21computers dang that is a really good
  238. 9:23looking
  239. 9:24computer that one not so much but we
  240. 9:26still love you and because both of these
  241. 9:29clients
  242. 9:30are retrieving data from the same Source
  243. 9:32they're going to see the same exact
  244. 9:34thing they are 100% in sync they are
  245. 9:37consistent there's also a term eventual
  246. 9:39consistency which we're going to get to
  247. 9:41in a second but let's just go with this
  248. 9:43for a second you're either going to be
  249. 9:45consistent or not consistent so let's go
  250. 9:47through the scenario where now instead
  251. 9:49of having just a single server you have
  252. 9:51two or three or more servers so now we
  253. 9:53have a scenario where we have three
  254. 9:56servers you could imagine these being
  255. 9:58database servers where these are storing
  256. 10:00data and each one of our clients access
  257. 10:04a different server the question of
  258. 10:06consistency is if all of these users are
  259. 10:09requesting the same piece of information
  260. 10:11let's say the user with the ID of five
  261. 10:14are they going to get the same result
  262. 10:16there's a scenario where they might not
  263. 10:18and that is if instead of just reading
  264. 10:21the data from one of these clients we
  265. 10:23actually updated it so let's say we
  266. 10:25changed the user's name from John to
  267. 10:29Caleb if our service is not consistent
  268. 10:32and these clients request that user
  269. 10:35information they might get the outdated
  270. 10:37information so this change would
  271. 10:39eventually propagate to this server and
  272. 10:42this one too but that takes a little bit
  273. 10:44of time right it takes time to copy that
  274. 10:46data over so if we make these requests
  275. 10:49at the perfect time right before that
  276. 10:52data is copied over we might get
  277. 10:54inconsistent results so let's go through
  278. 10:56the scenario we updated from John to
  279. 10:58Caleb So This Server is going to see
  280. 11:01Caleb because that data is in that
  281. 11:05server and then let's say that change
  282. 11:06propagates to This Server so when this
  283. 11:08computer tries to retrieve that user
  284. 11:10information it will also get
  285. 11:13Caleb so far so
  286. 11:16good however this one it didn't quite
  287. 11:20copy that data over in time and the
  288. 11:22request retrieves old data that hasn't
  289. 11:25been updated yet so this one's going to
  290. 11:27retrieve JN which is not correct the
  291. 11:31results are inconsistent I know I'm
  292. 11:33probably drilling this idea into your
  293. 11:35head a little too much but just
  294. 11:38understand when people say consistency
  295. 11:40it truly means are you getting
  296. 11:42consistent results across the server in
  297. 11:45this scenario you're getting
  298. 11:47John Caleb and Caleb so with this
  299. 11:51scenario if you were asked is this
  300. 11:53database setup consistent the answer
  301. 11:56would be no not consistent
  302. 12:02however when I'm saying consistent here
  303. 12:04I'm specifically referring to strong
  304. 12:07consistency so that's another word you
  305. 12:09should be familiar with and strong
  306. 12:11consistency means when there's a right
  307. 12:13that happens or some kind of change that
  308. 12:14change is going to be available
  309. 12:16immediately on all of the nodes there's
  310. 12:18another type which is eventual
  311. 12:20consistency and that is basically when
  312. 12:22there is a change eventually that'll be
  313. 12:25copied over to the other nodes it's just
  314. 12:27not immediate so let's erase this and
  315. 12:29then talk a little bit more in detail
  316. 12:31about the differences between strong
  317. 12:32consistency and eventual consistency and
  318. 12:35which one is correct or which one you
  319. 12:36should use or what you'll typically see
  320. 12:39so if we have a distributed system that
  321. 12:42is strongly consistent the way this is
  322. 12:44going to work is it's going to wait to
  323. 12:47confirm the change until all of the
  324. 12:50other nodes can also apply that change
  325. 12:54so just to save space here I'm going to
  326. 12:55draw those three nodes in a line here so
  327. 12:58we can have some more room to write and
  328. 13:00we make some change to the data on this
  329. 13:03node that change will be in a pending
  330. 13:05State it's not confirmed yet until that
  331. 13:08change is propagated to the other nodes
  332. 13:11and they have that change locally and
  333. 13:14they can all be applied so that the
  334. 13:17change is confirmed so in this situation
  335. 13:19you're not going to see any
  336. 13:20inconsistency because the change is
  337. 13:22applied to all of the nodes at the same
  338. 13:24time the major downside to this is it's
  339. 13:27going to take time we now now have to
  340. 13:29wait for that change to propagate to
  341. 13:32these other nodes before we can see that
  342. 13:34change confirmed on the main node we're
  343. 13:36working with the major benefit is
  344. 13:39consistency the other type of
  345. 13:41consistency we're going to talk about is
  346. 13:43eventual consistency which in my book
  347. 13:45would be not consistent but it's still a
  348. 13:49form of consistency because the other
  349. 13:51nodes will eventually get the data it's
  350. 13:53just not going to be immediate so with
  351. 13:55the eventual consistency we're going to
  352. 13:57have the same setup let's go with three
  353. 13:59nodes
  354. 14:01here and we make some change to a node
  355. 14:05so we update some data this will be
  356. 14:07immediately confirmed and then
  357. 14:10eventually that change will propagate to
  358. 14:12the other notes so there's a scenario if
  359. 14:15you access the data immediately after
  360. 14:17it's written to the right node that will
  361. 14:21get some inconsistent State and we're
  362. 14:23accessing stale
  363. 14:26data and this would only happen if you
  364. 14:29manage to access that data before that
  365. 14:32propagation happens from the main node
  366. 14:35can't really erase that blue too well so
  367. 14:37we could say it propagates to this one
  368. 14:39but it's not quite done propagating to
  369. 14:41this other node so when we access the
  370. 14:44data we get stale data so one client
  371. 14:47might receive something different than
  372. 14:49another client the person accessing this
  373. 14:51node will get the update data the person
  374. 14:54accessing this node since the
  375. 14:55propagation has completed will get the
  376. 14:57up toate data but the person accessing
  377. 14:59this node will get stale data the old
  378. 15:02data before it was updated so the major
  379. 15:04downside here is that the data is not
  380. 15:08consistent which means it's kind of not
  381. 15:10trustable the major benefit and I'm
  382. 15:12drawing a down arrow so don't be
  383. 15:14confused because we are going to reduce
  384. 15:17the time to write data we can write data
  385. 15:20and we don't have to wait for that to be
  386. 15:22confirmed on the other nodes before we
  387. 15:24can confirm the entire transaction so
  388. 15:27it's not a question of which one's right
  389. 15:29it's a question of which tradeoff do you
  390. 15:31prefer in an environment that's strongly
  391. 15:33consistent you're going to have
  392. 15:35consistent data across all the nodes but
  393. 15:38it's going to take a little bit more
  394. 15:39time to write data to the database in an
  395. 15:42eventual consistency environment you're
  396. 15:44not going to have that consistency right
  397. 15:46away but the time to write is going to
  398. 15:49be much faster which approach you take
  399. 15:51depends on the application so I'll write
  400. 15:53some scenarios where you might choose
  401. 15:55one over the other so a big one is going
  402. 15:58to be banking
  403. 16:01you can imagine a scenario where you
  404. 16:03transfer $100 is the last $100 you have
  405. 16:06and now your account says zero like
  406. 16:08usual the problem here is that someone
  407. 16:11could access your data on another node
  408. 16:13and still see that you have $100 and
  409. 16:15then make another transfer or that
  410. 16:17difference might make the difference
  411. 16:18between getting approved for a loan or
  412. 16:20not getting approved for a loan so
  413. 16:22anything dealing with money should be
  414. 16:23consistent other examples would be
  415. 16:26potentially medical stuff especially if
  416. 16:28it's real
  417. 16:29Time stuff that's like electronic health
  418. 16:32records probably not a big deal to be
  419. 16:34strongly consistent because that data
  420. 16:36doesn't change very often so it's really
  421. 16:38about reading old data consistency is
  422. 16:40really important when we're talking
  423. 16:42about new data being added or data being
  424. 16:44modified another example might be
  425. 16:47military you definitely don't want to
  426. 16:49have inconsistent State when you're
  427. 16:50trying to decide if you know you should
  428. 16:52fire a weapon like that's something
  429. 16:54where you want things to be consistent
  430. 16:56there is another big issue here which
  431. 16:58has to do with availability and the cap
  432. 17:00theorem which we're going to get into
  433. 17:02but basically one of the downsides of
  434. 17:04strong consistency is that it can harm
  435. 17:06your availability so we're going to get
  436. 17:08into that but this scenario would be if
  437. 17:11you have a medical scenario or a
  438. 17:14military scenario where differences in
  439. 17:17data could be detrimental so I'm going
  440. 17:19to write these in parentheses saying
  441. 17:21maybe just depending on the use case but
  442. 17:24definitely probably want to keep strong
  443. 17:26consistency with anything Financial
  444. 17:29so let's talk about eventual consistency
  445. 17:31some examples of when you might prefer
  446. 17:33this route would be social media or
  447. 17:36other basic crud apps create read update
  448. 17:39delete basically websites or apps where
  449. 17:42you're changing some data you know you
  450. 17:44might post a status but if that doesn't
  451. 17:46show up for people for a couple of
  452. 17:47seconds it's really not that big of a
  453. 17:49deal you're not doing any real-time
  454. 17:50trading or anything like that so it's
  455. 17:52not the end of the world if you get some
  456. 17:53stale data especially if it's only stale
  457. 17:56for a brief period of time next up we're
  458. 17:58going to talk about scalability and
  459. 18:00honestly of all the words if if you're
  460. 18:03talking to somebody in
  461. 18:05marketing or you know the CEO as long as
  462. 18:08your app is scalable that's all that
  463. 18:10matters so you can ignore all the other
  464. 18:12stuff so it's a buzzword but there's a
  465. 18:14lot more to it what does it mean if an
  466. 18:16app is scalable the summary is that your
  467. 18:18app is able to support an increase in
  468. 18:22the workload which could come from a
  469. 18:24spike in traffic or particular parts of
  470. 18:27the year maybe Black Friday you need
  471. 18:29more computing power so you can support
  472. 18:32the new users one of the easiest ways to
  473. 18:35achieve scalability is with over
  474. 18:37provisioning so if you imagine this
  475. 18:39being your server that runs your
  476. 18:42application and we're not going to get
  477. 18:44into splitting out the database and the
  478. 18:46backend API let's just keep it General
  479. 18:48here this is our application and inside
  480. 18:52of the server you have a certain amount
  481. 18:53of computing power CPU RAM and even
  482. 18:57storage whether that's hard disks or
  483. 19:00ssds and let's say the utilization of
  484. 19:03the server is down here so you're really
  485. 19:06not using all of your computing power
  486. 19:08maybe 20% so that's okay and you know
  487. 19:11you could probably go a little higher or
  488. 19:12a little higher but as you start to get
  489. 19:15to using the majority of your Computing
  490. 19:18resources now you're going to start
  491. 19:19having issues and I'm going to say that
  492. 19:21that's bad so you want to have a little
  493. 19:23bit of space between how much Computing
  494. 19:26you need which in this case what we
  495. 19:28wrote was is right here this is what we
  496. 19:30need and the max you could support so
  497. 19:34from day to day you don't want to be
  498. 19:35capped out but also consider the cases
  499. 19:38where you might have spikes perhaps it's
  500. 19:40a certain time of day every day at 8:00
  501. 19:43a.m. you have more traffic so you want
  502. 19:46to consider not only the typical usage
  503. 19:49but also what might be the most usage
  504. 19:52that you need so this is just a visual
  505. 19:54to show how much computing power you
  506. 19:55might need compared to how much you have
  507. 19:58available you might only be using half
  508. 20:00of the available processing power for
  509. 20:03example if the amount of compute you
  510. 20:05need for Peak usage is well within the
  511. 20:08max then you have a scalable service
  512. 20:10because even in the worst case scenario
  513. 20:12where you hit that Peak usage you still
  514. 20:14have all of this space and you want to
  515. 20:16avoid getting into the areas where
  516. 20:18you're almost maxing out the computer so
  517. 20:21let's say there are scenarios where
  518. 20:23typical usage is well within the realm
  519. 20:26of this computer but there are certain
  520. 20:28times maybe once a year or once a
  521. 20:30quarter where you need even more than
  522. 20:33what's allowed in this server you're
  523. 20:35going to have to do something else to
  524. 20:37scale this app so there are a few
  525. 20:39different approaches to scalability
  526. 20:42Beyond just overr provisioning having
  527. 20:45some massive server and just hoping you
  528. 20:47never reach the max what if you do reach
  529. 20:49the max what do you do there's a couple
  530. 20:52of different approaches we're going to
  531. 20:53talk about the first one being vertical
  532. 20:56scaling and the second one being
  533. 20:57horizontal scal scaling vertical scaling
  534. 21:00the idea is simple we just add more
  535. 21:02Computing resources practically that
  536. 21:04means if this was your previous server
  537. 21:07you can
  538. 21:08upgrade getting a new server or adding
  539. 21:11more processing power more RAM but we
  540. 21:14still go from one server to one server
  541. 21:18it's just a stronger server this is
  542. 21:21often also called scaling
  543. 21:24up we're just increasing the Computing
  544. 21:27resources but we're still within a
  545. 21:29single server horizontal scaling on the
  546. 21:31other hand is actually adding servers so
  547. 21:34instead of just having this little
  548. 21:36server you could have multiple of these
  549. 21:39little servers working in unison or you
  550. 21:42could do a combination of both but just
  551. 21:45to finish this real quick this would be
  552. 21:47scaling
  553. 21:49out the combination would basically be
  554. 21:52not only adding servers but also
  555. 21:54increasing the computing power so that
  556. 21:56might be going from this to
  557. 21:59now having even bigger servers so it
  558. 22:01might look something like that so a
  559. 22:03single server may not have been able to
  560. 22:05scale enough and even increasing some of
  561. 22:08the computing power might introduce
  562. 22:11limitations if you're at a really large
  563. 22:13scale so you can go from one server to
  564. 22:17two or more servers and now you should
  565. 22:19be able to maintain enough computing
  566. 22:22power to handle all of the requests so
  567. 22:25this might happen say once a year the
  568. 22:27actual frequency would vary completely
  569. 22:29based on what kind of app you're
  570. 22:31building but the challenge is you
  571. 22:34probably don't need Max scaling all the
  572. 22:37time because applications often grow and
  573. 22:41decrease in their usage for various
  574. 22:43times of the day or various times of the
  575. 22:45year so a very similar word but a little
  576. 22:48bit different more focused on the
  577. 22:49ability to grow and Shrink is elasticity
  578. 22:52so with scalability when there's an
  579. 22:54increase in the workload we just
  580. 22:56increase the compute
  581. 22:59so it looks like
  582. 23:01this however this may require manual
  583. 23:04intervention and it's typically more
  584. 23:06worried about the increase in workload
  585. 23:09whereas elasticity deals with an
  586. 23:12increase in workload and then eventually
  587. 23:15a decrease in workload when the workload
  588. 23:18is higher we will increase the computing
  589. 23:21power and then when the load is lower we
  590. 23:25will decrease the computing power
  591. 23:30so elasticity is the ability for an app
  592. 23:33to automatically adjust based on Usage
  593. 23:37Now that might be confusing like how
  594. 23:39could you just always be adding hardware
  595. 23:42and removing hardware and typically it's
  596. 23:45going to be done by some cloud provider
  597. 23:48so when you're looking at Cloud
  598. 23:49providers to host applications you can
  599. 23:51check to see if the service is elastic
  600. 23:53and it will do the growth and decrease
  601. 23:56behind the scenes for you and because
  602. 23:58these applications are often virtualized
  603. 24:00they might not actually be adding a
  604. 24:03processor to your computer and then
  605. 24:05removing a processor they just have a
  606. 24:07bunch of servers that will run all of
  607. 24:10the applications and then allocating
  608. 24:12more or less resources for any
  609. 24:14particular application so that's how a
  610. 24:17cloud provider can easily allow for
  611. 24:19elasticity without technicians being in
  612. 24:21there manually adding and removing
  613. 24:23Hardware all of the time so these words
  614. 24:25are very similar and you might hear them
  615. 24:27used interchange but if we're going to
  616. 24:29try to be as clear as possible I would
  617. 24:31say scalability is focusing on having
  618. 24:33enough computing power for an increased
  619. 24:35workload without having your application
  620. 24:38shut down or you know just completely
  621. 24:40break this can be achieved various ways
  622. 24:42whether that's manual intervention or
  623. 24:43some automatic setup even if it's just
  624. 24:45over provisioning and having more
  625. 24:47Hardware than you really need one step
  626. 24:49further would be elasticity where the
  627. 24:51compute is automatically adjusted either
  628. 24:53up or down based on the current workload
  629. 24:56now just to review and make sure we're
  630. 24:58all on the same page the scalability
  631. 25:00does not refer to a Services
  632. 25:03availability you could have one server
  633. 25:06that you just increase the amount of
  634. 25:08computing power it has to increase the
  635. 25:10scalability but that doesn't necessarily
  636. 25:12mean it's highly available because you
  637. 25:14could still have one server and if that
  638. 25:16server breaks well your entire service
  639. 25:19goes down doesn't matter if you have the
  640. 25:21most powerful computer in the entire
  641. 25:24world if it goes down for some reason
  642. 25:27you're still kind of screwed because you
  643. 25:29don't have any backup computers so that
  644. 25:31idea is known as a single point of
  645. 25:33failure so a single point of failure you
  646. 25:35can think of it as any Link in a chain
  647. 25:38that does not have any kind of high
  648. 25:40availability or redundancy so that's
  649. 25:43another word we're going to write down
  650. 25:45here so redundancy is just having an
  651. 25:47extra there in case something goes wrong
  652. 25:49with the main one kind of how you would
  653. 25:51have a spare tire with your car if you
  654. 25:53have a flat you can swap out one of your
  655. 25:56wheels with the spare and you can still
  656. 25:58function it's often the case that in
  657. 26:00real life people think of redundancy as
  658. 26:03a bad thing if something's redundant we
  659. 26:05don't need it so get rid of it however
  660. 26:08in Computing It's usually the opposite
  661. 26:10we want redundancy so redundancy is
  662. 26:13usually a good thing a single point of
  663. 26:15failure is usually a bad thing so we're
  664. 26:19going to make sure this is really clear
  665. 26:21drawing these faces redundancy it can
  666. 26:24add cost but it can make sure a service
  667. 26:27stays available consider the case where
  668. 26:29we have some database server and let's
  669. 26:31say we're connecting to this from some
  670. 26:33Advanced backend which has load
  671. 26:35balancing and a bunch of servers so this
  672. 26:38is great there's no single point of
  673. 26:40failure here and then we're connecting
  674. 26:42to it from some Advanced front end as
  675. 26:45well so checking if these have
  676. 26:46redundancy let's say the front end does
  677. 26:48have redundancy the back end has
  678. 26:50redundancy but we get to the database
  679. 26:53layer and it does not have redundancy
  680. 26:56this would be our single point of
  681. 26:57failure and when we're trying to build
  682. 26:59highly available systems our job is to
  683. 27:01identify single points of failure and
  684. 27:03try to remove them with various
  685. 27:05approaches the usual First Step would be
  686. 27:07to add redundancy so if we add in a
  687. 27:10standin server which is just going to
  688. 27:12act as a replacement if the main server
  689. 27:15fails for some reason you can imagine
  690. 27:18this server explodes the data center
  691. 27:21disappears something terrible happens
  692. 27:24well this server is ready to go has all
  693. 27:26of the data the same as this server it's
  694. 27:29consistent with the main database this
  695. 27:32would immediately be promoted and our
  696. 27:35traffic would route to that new database
  697. 27:38instance this standin is a little bit
  698. 27:41different than the back end where we
  699. 27:43might have multiple servers all sharing
  700. 27:45the load the standin in this scenario
  701. 27:48does not take any of the traffic
  702. 27:50typically it just acts as an emergency
  703. 27:52fill in if something goes wrong with the
  704. 27:55primary database so that is an example
  705. 27:57of redundancy anytime we add redundancy
  706. 28:00we're probably going to add cost because
  707. 28:03we now have to maintain two database
  708. 28:06instances another important word you
  709. 28:08should know is Fault tolerant or fault
  710. 28:11tolerance so we created a fault tolerant
  711. 28:14system A system that will still function
  712. 28:17if something goes wrong by removing
  713. 28:20single points of failures and we remove
  714. 28:22the single point of failure by using
  715. 28:24redundancy having a standin database in
  716. 28:26case something goes wrong so fault
  717. 28:28tolerance that's a general term to
  718. 28:30describe what we did we created a system
  719. 28:33that is tolerant to faults by adding in
  720. 28:37new things such as redundant servers so
  721. 28:40by removing single points of failures we
  722. 28:43can achieve fault tolerance and we do
  723. 28:47that through adding redundancy the
  724. 28:49specific thing we did to introduce
  725. 28:52redundancy in our application is
  726. 28:54database replication so we pretty much
  727. 28:57just created a replica
  728. 28:58from the primary node to the secondary
  729. 29:01node which that's another word we've
  730. 29:03been throwing around but the term node
  731. 29:05just means one of the computers in a
  732. 29:08multicomputer setup where a computer is
  733. 29:12a server so a node is a server which you
  734. 29:16can just kind of think of as a computer
  735. 29:17designed to run something such as a
  736. 29:20database for some of you who've worked
  737. 29:21with databases and servers before that
  738. 29:23might be super obvious but if you're
  739. 29:25just a beginner getting started people
  740. 29:27throw a lot of these words out without
  741. 29:29really describing what exactly they mean
  742. 29:31so a node would just be one of these or
  743. 29:35this would be another node and the idea
  744. 29:37of replication is creating a duplicate
  745. 29:40node let's zoom in a little bit more on
  746. 29:43databases and talk about some terms with
  747. 29:45that so when we're working with the
  748. 29:47database and we get to the point of not
  749. 29:49just having a single instance or a node
  750. 29:52and we actually want multiple nodes
  751. 29:54might look something like this you could
  752. 29:56call this entire thing
  753. 29:59a database cluster now when you're
  754. 30:01talking about databases and database
  755. 30:03clusters there are various setups you'll
  756. 30:05see so this isn't going to be the only
  757. 30:08way you will see it but a very common
  758. 30:10scenario is you'll just have one master
  759. 30:14node and then the rest being slave nodes
  760. 30:18or you could just say that this is a
  761. 30:20right
  762. 30:23node and these are read nodes so we kind
  763. 30:26of showed this already earlier where you
  764. 30:28write to a node and then that data is
  765. 30:32given to the other nodes in the system
  766. 30:35so you can think of both of these as
  767. 30:41replicas and then it's just a matter of
  768. 30:43do we want these to be strongly
  769. 30:46consistent or eventually consistent so
  770. 30:48we already understand the idea of
  771. 30:51consistency and we already talked about
  772. 30:53how if something is consistent it takes
  773. 30:55more time to make that right but to get
  774. 30:57a little bit more technical on the
  775. 30:59terminology when we make these replicas
  776. 31:02the act of replicating replication has
  777. 31:06two different approaches which would be
  778. 31:09synchronous which would be
  779. 31:13consistent and what this will do is it
  780. 31:16will replicate the data over and it will
  781. 31:19do it synchronously waiting for the
  782. 31:22result so all of the nodes have to write
  783. 31:26the data in order for for the data to be
  784. 31:29confirmed so nothing different than what
  785. 31:31we've already talked about with
  786. 31:33consistency it's just you might also
  787. 31:35hear the term synchronous replication
  788. 31:38comparing that to
  789. 31:40asynchronous which will basically just
  790. 31:42send data over as it gets
  791. 31:46it not really worried about the time it
  792. 31:49takes for that data to be confirmed on
  793. 31:52the replicas so this node can still be
  794. 31:55doing things while these other nodes are
  795. 31:58writing that data and that's the whole
  796. 32:00idea of it being asynchronous so that is
  797. 32:03eventually consistent now the change in
  798. 32:05time that synchronous replication is
  799. 32:07going to cause is called
  800. 32:11latency so latency is just a measure of
  801. 32:15how long something takes from request to
  802. 32:18response so say this is me and if we're
  803. 32:20just talking about General latency here
  804. 32:22I make a request to a web page and that
  805. 32:25web page shows up after say 100
  806. 32:28[Music]
  807. 32:30milliseconds this is the idea of latency
  808. 32:34but you could obviously split that out
  809. 32:36at different levels so we could talk
  810. 32:37about latency at the database level and
  811. 32:40when things are consistent the latency
  812. 32:42is going to go up so just another word
  813. 32:45you should be familiar with it's going
  814. 32:46to worsen the overall user experience
  815. 32:48because the time from request to
  816. 32:50response is longer now in this scenario
  817. 32:53we just have one primary node and then
  818. 32:57two re read replicas when we're getting
  819. 33:00deeper into database clustering it could
  820. 33:01be the case that we have multiple write
  821. 33:04nodes so what if we not only wrote to
  822. 33:09this node but we could also write to
  823. 33:11this node that's going to introduce more
  824. 33:13interesting challenges and while I think
  825. 33:15this is important to understand the
  826. 33:18first step in terms of growing your app
  827. 33:20for scalability and availability would
  828. 33:23be to introduce reading nodes and just
  829. 33:25directing read traffic to the read nodes
  830. 33:28and right traffic to the right node
  831. 33:30however if we want a multimaster setup
  832. 33:32then we have to talk about more advanced
  833. 33:33database clustering techniques which is
  834. 33:36probably something we're going to get
  835. 33:37into in more detail later on in this
  836. 33:39series so for now for our basic example
  837. 33:42just imagine there being a single write
  838. 33:45node and then multiple read replicas
  839. 33:49that's usually pretty good because it's
  840. 33:51often the case that applications will be
  841. 33:53more read heavy and not write heavy so
  842. 33:57you might read 80% of the time and write
  843. 33:5920% of the time so you can have more
  844. 34:03read replicas and individually scale
  845. 34:06these keeping just a single right node
  846. 34:10and then when it comes to redundancy you
  847. 34:12can have a backup write
  848. 34:14node that's not actively used for
  849. 34:17writing but acts as a standin if for
  850. 34:20some reason our right node goes down we
  851. 34:23can direct traffic to the standin node
  852. 34:26but they're not both being used used for
  853. 34:28writing at the same time which
  854. 34:29introduces various other challenges so
  855. 34:32if you don't have multiple write nodes
  856. 34:34the structure is pretty simple even
  857. 34:36though I drew a bunch of complex lines
  858. 34:38and circles here the general idea is you
  859. 34:41just have a right node possibly a
  860. 34:43standin node for redundancy and then
  861. 34:45you'll have read replicas which are
  862. 34:48either consistent or eventually
  863. 34:50consistent we have talked about a lot
  864. 34:53and a lot of database stuff as well
  865. 34:55we're going to do a little bit more
  866. 34:56about databases but this time we're not
  867. 34:58going to talk about databases with
  868. 35:00replication in a distributed environment
  869. 35:03instead we're going to talk about just a
  870. 35:04single database instance because even on
  871. 35:07a single computer there are certain
  872. 35:08rules we want to enforce to make sure
  873. 35:10our database is usable and trustworthy
  874. 35:13so you may have heard of the term acid
  875. 35:16uh not like the stuff that like melts
  876. 35:20stuff or like the drugs but acid in
  877. 35:22databases so you may have heard of
  878. 35:25databases being acid compliant and what
  879. 35:28in the world does that mean that's what
  880. 35:30we're going to talk about this is an
  881. 35:31acronym for four different properties of
  882. 35:34databases now this is what most
  883. 35:36databases are going to strive for and
  884. 35:38most relational databases are going to
  885. 35:40be acid compliant there are certain
  886. 35:43databases out there that do not meet all
  887. 35:45of these expectations for various
  888. 35:47reasons but this is a general starting
  889. 35:49point so if you're working with a
  890. 35:50typical SQL database such as postgress
  891. 35:53this is going to be an acid compliant
  892. 35:55database so we're going to go over these
  893. 35:57very briefly and we may do a dedicated
  894. 35:59video to this topic just depending on
  895. 36:01how much information I want to cover on
  896. 36:04these things but I just think it's a
  897. 36:05good idea to know that they exist and be
  898. 36:07lightly familiar with what they are so
  899. 36:10atomicity believe that's how it's
  900. 36:12pronounced basically the idea of
  901. 36:14something being a single unit you can
  902. 36:16think of an atom even though you can
  903. 36:17split atoms a good example of this would
  904. 36:20be if you run a transaction the
  905. 36:23transaction will either succeed or it
  906. 36:25will fail it's one unit you can't have a
  907. 36:27partial completions so transactions will
  908. 36:30either succeed or they will fail
  909. 36:33consistency this can be a bit confusing
  910. 36:35because we've been talking about
  911. 36:36consistency this entire video but this
  912. 36:38consistency is actually referring to a
  913. 36:40different kind of consistency so why
  914. 36:42they're not consistent with the usage of
  915. 36:44the term consistent is beyond me but the
  916. 36:48consistency here is referring about
  917. 36:50State changes in the database so when
  918. 36:52you do some processing your database
  919. 36:54starts in one state and will move to
  920. 36:58another valid state so this is a valid
  921. 37:00State and this is a valid State meaning
  922. 37:03any change is required to adhere to any
  923. 37:06kind of Integrity rules you set at the
  924. 37:08database level so we haven't gotten into
  925. 37:10a ton of the details of databases in
  926. 37:13this series yet but an example would be
  927. 37:15referential Integrity so I'll just write
  928. 37:17up here respecting foreign keys so you
  929. 37:21can't create a change in the database
  930. 37:22that breaks some defined rules that you
  931. 37:24created for the database this helps your
  932. 37:27data have integrity which means it's
  933. 37:29correct and trustworthy isolation you
  934. 37:32can think of individual transactions as
  935. 37:35being isolated not dependent on other
  936. 37:38transactions that might be happening
  937. 37:40concurrently so I just put independent
  938. 37:43execution I was trying to think of a way
  939. 37:44to describe it without using isolation
  940. 37:46in the definition this would be kind of
  941. 37:48cool one to go into in more detail
  942. 37:50because that's pretty vague so you can
  943. 37:53look into concurrency stuff with
  944. 37:55whatever database you are using and then
  945. 37:57durability is basically data
  946. 38:00permanence once the data is committed or
  947. 38:03saved it's permanently saved even if
  948. 38:05there was a power outage right after
  949. 38:08that saving is a checkpoint and you
  950. 38:11wouldn't ever expect to have your system
  951. 38:13go back to before that committed data so
  952. 38:16you can trust changes to persist in an
  953. 38:19acid compliant database another database
  954. 38:22word I want to talk about is
  955. 38:25sharding and this is a specific type of
  956. 38:28database
  957. 38:29partitioning so two words we need to
  958. 38:31talk about real
  959. 38:35quick so database partitioning can
  960. 38:38happen at the individual database level
  961. 38:41or within a larger database cluster So
  962. 38:44within an individual database let's just
  963. 38:45say we have one database server you
  964. 38:47might have some massive table this table
  965. 38:50might be massive because it has a lot of
  966. 38:53columns so you can imagine it being
  967. 38:55split up a lot this way
  968. 38:58and one individual row might have a ton
  969. 39:00of data because has data for all of
  970. 39:02those columns so you could optimize
  971. 39:05performance with this table by splitting
  972. 39:07up the table into multiple tables
  973. 39:10typically you're not going to have to do
  974. 39:11this unless you're really working with
  975. 39:13big data but it would look like this you
  976. 39:15split it and now we might have a table
  977. 39:17with this section and a table with this
  978. 39:20section and then you can just connect
  979. 39:21rows with the foreign key so this would
  980. 39:23be vertical partitioning
  981. 39:27horizontal partitioning works pretty
  982. 39:30similar but instead of splitting by
  983. 39:32column we'll split the data so you can
  984. 39:35imagine if you had a bunch of rows you
  985. 39:37can split the data so that the rows are
  986. 39:40split up instead of the columns so for
  987. 39:42example this row might be assigned one
  988. 39:45this one might be assigned two and then
  989. 39:47this one might be assigned three and
  990. 39:49then again one and then
  991. 39:53two and so forth where now if we wanted
  992. 39:57to to just access a certain subset of
  993. 40:00this data such as anyone from partition
  994. 40:04one we would only be working with two
  995. 40:06rows instead of the entire data set so
  996. 40:09you can imagine the ones twos and threes
  997. 40:11being split up across different tables
  998. 40:14kind of and then it's just a matter of
  999. 40:16knowing which table to access to get the
  1000. 40:18correct information so again we're just
  1001. 40:21going very surface level we'll get into
  1002. 40:23partitioning in a lot of detail so don't
  1003. 40:25feel like you have to understand all of
  1004. 40:26it in this video video the general idea
  1005. 40:29is we can reduce the row count by just
  1006. 40:32working with a subset of the rows in
  1007. 40:34this case just my madeup example of
  1008. 40:37labeling them one two or three so that
  1009. 40:41is an example of
  1010. 40:44horizontal
  1011. 40:46partitioning so this can all be done
  1012. 40:48within the same database instance So
  1013. 40:51within postgress for example you could
  1014. 40:53just split up your table into two
  1015. 40:55different tables with a subset of
  1016. 40:57columns or postrest supports horizontal
  1017. 41:00partitioning so it can basically do this
  1018. 41:03for you and then give you like a virtual
  1019. 41:05table to see all of the data whereas
  1020. 41:08creating the virtual table to see all of
  1021. 41:10the data over here would be to create a
  1022. 41:12view so again we're getting into the
  1023. 41:15details but basically partitioning can
  1024. 41:18be done at just an individual database
  1025. 41:20level without having to worry about
  1026. 41:23replication or distributed computing
  1027. 41:26however if you want to take this idea
  1028. 41:27and go one step further across different
  1029. 41:31nodes that is what sharding is you might
  1030. 41:34be able to use those terms
  1031. 41:35interchangeably but typically when
  1032. 41:38people are talking about sharding it's
  1033. 41:39because they want to split the data up
  1034. 41:42across nodes so then instead of just
  1035. 41:45having replicas for fault tolerance and
  1036. 41:48potentially independently scaling the
  1037. 41:51reads and writes now you could actually
  1038. 41:53split the data across multiple nodes and
  1039. 41:56only have for example in this case a
  1040. 41:59third of the data to deal with so you
  1041. 42:02could imagine assigning each one of
  1042. 42:03these to its own database node so that
  1043. 42:06is a very high level of what sharding is
  1044. 42:09and how it works but there's a lot to it
  1045. 42:11and we'll get into you know how do we
  1046. 42:13decide how to split up this data how's
  1047. 42:15that work inside of a database cluster
  1048. 42:18because it's not always the case that
  1049. 42:19the database cluster will have complete
  1050. 42:21notes sometimes they will just have a
  1051. 42:23subset of the data because they're using
  1052. 42:25sharding
  1053. 42:27and I'm saying sharding not sharting by
  1054. 42:29the way wow we went through a lot of
  1055. 42:32material introducing many different
  1056. 42:34topics my goal here was to give you like
  1057. 42:37the intro to each major topic so now you
  1058. 42:39have a better idea of what we're going
  1059. 42:41to conquer in Greater detail in the
  1060. 42:42upcoming lessons so the takeaways from
  1061. 42:44this video Dang applications can be
  1062. 42:46pretty complex behind the scenes there's
  1063. 42:48actually a whole other world that I
  1064. 42:50didn't introduce which is caching that's
  1065. 42:52something we're going to do dedicated
  1066. 42:54videos on so we're not going to get into
  1067. 42:56it much detail here the main thing you
  1068. 42:59need to know about caching is it's a way
  1069. 43:01that you can temporarily store data for
  1070. 43:04easy fast access to reduce the
  1071. 43:06computation needed on the API or the
  1072. 43:10database layer so if we can remove a
  1073. 43:12substantial number of requests that need
  1074. 43:14to be made to the database we probably
  1075. 43:16don't have to worry about all of this
  1076. 43:18crazy database setup stuff nearly as
  1077. 43:21soon the main thing you would just want
  1078. 43:23to do is have the availability by having
  1079. 43:25that standin node and and then just
  1080. 43:27scale your node vertically not having to
  1081. 43:30worry about complex clustering setups
  1082. 43:33another takeaway from this that you will
  1083. 43:35benefit from which we didn't get into a
  1084. 43:37lot but there's various cloud services
  1085. 43:39you can use that will often abstract
  1086. 43:42away a lot of this for you so for
  1087. 43:44example you might be using a cloud
  1088. 43:46database and that cloud database might
  1089. 43:48be
  1090. 43:49serverless and this doesn't mean that
  1091. 43:51there is no servers being used for the
  1092. 43:54database it just means that it's fully
  1093. 43:56managed so you pay for
  1094. 44:00use and it is elastic basically growing
  1095. 44:03and shrinking completely handsfree this
  1096. 44:06can get expensive but it's very
  1097. 44:09convenient because you don't have to
  1098. 44:10worry about a lot of the stuff we're
  1099. 44:12talking about here so there are a lot of
  1100. 44:13options out there where you basically
  1101. 44:15pay for usage and it's fully managed
  1102. 44:18which could actually be beneficial if
  1103. 44:20you're accidentally overr provisioning
  1104. 44:22your servers you might be wasting money
  1105. 44:25so having either elastic features with
  1106. 44:27that main server or just going
  1107. 44:29completely serverless could actually
  1108. 44:31save you some money so just definitely
  1109. 44:33something you should look into and at
  1110. 44:34least be aware that serverless databases
  1111. 44:37are a thing and can be pretty handy
  1112. 44:39they'll do all of the clustering and
  1113. 44:42database management for you behind the
  1114. 44:44scenes at this point you have a pretty
  1115. 44:46good idea of the general structure for
  1116. 44:48software architecture and now going into
  1117. 44:51the upcoming videos you'll be much more
  1118. 44:53equipped to fill in knowledge and learn
  1119. 44:55all of these things at a deeper level I
  1120. 44:57look forward to seeing you in the next
  1121. 44:58video if you've enjoyed the content
  1122. 45:00please be sure to subscribe and check
  1123. 45:01out my resource links down below if you
  1124. 45:04want some additional help and useful
  1125. 45:06resources thank you I'll see you in the
  1126. 45:08next one

About this transcript

This page contains the full transcript of Essential System Design Concepts You Should Know - System Design Tutorial by Caleb Curry, generated from the public captions YouTube serves with the video. The transcript has 7,752 words across 1,126 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.