YouTube2Text

CS75 (Summer 2012) Lecture 9 Scalability Harvard Web Development David Malan — Transcript

by archn · 19,464 words · 2,766 segments · language en · Watch on YouTube

Full transcript

  1. 0:09welcome back to computer science s75
  2. 0:11this is lecture nine our very last it
  3. 0:13has been a pleasure having everyone in
  4. 0:15the course this semester um so tonight
  5. 0:17we talk about scalability so we try to
  6. 0:19revisit some of the topics that we
  7. 0:20looked at earlier in the semester and
  8. 0:22think about how we can deploy
  9. 0:24applications not just on say a virtual
  10. 0:26machine on your laptop or desktop as
  11. 0:28we've been doing with the appliance but
  12. 0:30you can scale to servers on the internet
  13. 0:32and indeed multiple servers on the
  14. 0:33internet so that you can handle hundreds
  15. 0:35or thousands or tens of thousands or
  16. 0:37even more than that in theory so some of
  17. 0:40the issues that we'll inevitably
  18. 0:42encounter is how to go about doing this
  19. 0:44so when it comes time to put something
  20. 0:46on the Internet recall from lecture zero
  21. 0:47that we talked about web host so this is
  22. 0:49by no means a list of recommendations
  23. 0:51per se it's just some representative
  24. 0:53ones that we happen to recommend um if
  25. 0:55only because the teaching fellows and I
  26. 0:57have had prior experiences with these
  27. 0:59particular vendors um but you can Google
  28. 1:01around and you can see that there's many
  29. 1:02many many different options these days
  30. 1:04however among the takeaways hopefully
  31. 1:06from the summer thus far has been what
  32. 1:09kinds of featur should you be looking
  33. 1:10for or expecting minimally in any web
  34. 1:13hosting company that you might
  35. 1:16choose and in fact not all of these even
  36. 1:19have those features
  37. 1:21necessarily
  38. 1:25accessibility example I have
  39. 1:28Aver Daddy my access isos Ser to have s
  40. 1:34to the post interesting okay good so if
  41. 1:37you're if you're country or your work or
  42. 1:39really any network that you happen to be
  43. 1:41on or people that you know happen to be
  44. 1:42on block access to certain IP ranges
  45. 1:45among them for instance God daddies in
  46. 1:47this case YouTube is a popular thing to
  47. 1:49block Facebook is a popular thing to
  48. 1:50block um that can be a sticking point so
  49. 1:53doing a bit of do diligence or testing
  50. 1:55first can be a good thing what else
  51. 1:58should you look for in a hosting company
  52. 2:01company Isaac SFTP good SFTP in contrast
  53. 2:06with what FTP FTP and why because ft
  54. 2:10SFTP is secure okay good so the S
  55. 2:13literally stands for secure and what
  56. 2:14that means is that all of your traffic
  57. 2:16is encrypted and this maybe isn't a big
  58. 2:18deal for the files that you're
  59. 2:19transferring because after all if you're
  60. 2:21uploading like gifs and jpegs and video
  61. 2:23files that are meant to be downloaded by
  62. 2:25people on the web well then who really
  63. 2:26cares if you encrypt those between your
  64. 2:28machine and the server but it is
  65. 2:30important to have what data
  66. 2:32encrypted Jack usernames passwords
  67. 2:35anything of exactly usernames and
  68. 2:37passwords right I mean that's one of the
  69. 2:39biggest failings of something like FTP
  70. 2:41which granted is a fairly dated or older
  71. 2:43protocol is that it sends also your
  72. 2:45username and password in the clear which
  73. 2:47means anyone sniffing wirelessly around
  74. 2:49you anyone sniffing the wi Network
  75. 2:51between point A and B can see in the
  76. 2:53clear what your username and password
  77. 2:54are yeah we looked at some hosting
  78. 2:57companies that offer unlimited
  79. 2:59everything for a really low price that
  80. 3:01could be due to um um virtual hosting
  81. 3:06and if you want to implement A system
  82. 3:08that can grow by itself you maybe don't
  83. 3:10want to share the same computers the
  84. 3:12same the same server with many others
  85. 3:15good so dream host in particular I think
  86. 3:17we pulled up their feature list and it
  87. 3:19was ridiculous how many features they
  88. 3:21give you unlimited bandwidth unlimited
  89. 3:23storage space unlimited Ram or something
  90. 3:25like that and that just can't possibly
  91. 3:27be uh real if you're only paying like
  92. 3:31$9.95 a month so there's some catch and
  93. 3:33in general the catch is that they're
  94. 3:35making that offer to you and to 100 to
  95. 3:37hundreds of other customers all of whom
  96. 3:40might be on that same machine so you're
  97. 3:42contending now for resources and the
  98. 3:43reality is they're probably banking in
  99. 3:45the fact that 90 something per of their
  100. 3:46customers don't need that many resources
  101. 3:49but for the one person or two persons
  102. 3:50that do probably going the way of a
  103. 3:52shared host is not necessarily in your
  104. 3:54best interest certainly not something to
  105. 3:55try to build a bigger business on and so
  106. 3:58there's alternatives to things like web
  107. 3:59hosting companies there's vpss a virtual
  108. 4:02private server that you can essentially
  109. 4:05rent for yourself and what's the
  110. 4:07fundamental distinction between a VPS
  111. 4:09and a shared web
  112. 4:11post Axel well VPS is like our Linux
  113. 4:16it's a it's it's virtual own machine
  114. 4:18running on a box but it's it's
  115. 4:20completely its own system okay good well
  116. 4:22and so be to be clear the operating
  117. 4:24system is largely irrelevant since dream
  118. 4:26host and shared web host could also be
  119. 4:27running Fedora or any operating system
  120. 4:29but what's key is that you get your own
  121. 4:31copy of Fedora or Ubuntu or whatever
  122. 4:34operating system they happen to be
  123. 4:35running because in the world of VPS is
  124. 4:37what they do is they take generally a
  125. 4:38super fast server with lots of ram lots
  126. 4:40of CPU lots of dis space and they chop
  127. 4:43it up into the illusion of multiple
  128. 4:45servers using something called a
  129. 4:46hypervisor something like a product from
  130. 4:48VMware or Citrix or other companies and
  131. 4:52even open source providers have
  132. 4:53platforms that allow you to do this run
  133. 4:56multiple uh virtual machines on a
  134. 4:58physical machine and so in this world
  135. 5:00you're still sharing resources but
  136. 5:02different typ uh in a different way
  137. 5:04you're instead getting some slice of
  138. 5:07Hardware to yourself and no one else has
  139. 5:10user accounts on that particular virtual
  140. 5:12machine now with that said the system
  141. 5:14administrators the owners of the VPS
  142. 5:17company they themselves depending on
  143. 5:19what hypervisor they're using they might
  144. 5:21actually have access to your virtual
  145. 5:22machine and to your files and frankly if
  146. 5:24you have physical access to the machine
  147. 5:26you undoubtedly have access to your
  148. 5:28files because they can always reboot the
  149. 5:30virtual machine for instance in what's
  150. 5:32called single user mode or diagnostic
  151. 5:34mode and at that point it's not they're
  152. 5:35not even prompted for a root password so
  153. 5:37realize that even when you're using a
  154. 5:39VPS your data might be more secure more
  155. 5:42private from other customers but
  156. 5:44definitely not the web hosting company
  157. 5:46itself if you want even more privacy
  158. 5:48than that you're probably going to have
  159. 5:49to operate your own servers that only
  160. 5:51you or your colleagues have physical
  161. 5:53access to so here's just a list of some
  162. 5:55of the popular VPS companies there is
  163. 5:57one catch in order to get these
  164. 5:59additional features or these uh
  165. 6:01properties in a VPS you generally pay
  166. 6:04more so instead of $10 a month $20 a
  167. 6:06month you're probably starting it $50 a
  168. 6:08month or something like that maybe even
  169. 6:10in the hundreds depending on how many
  170. 6:12how much you want in the way of um uh
  171. 6:15resources and toward the end of today
  172. 6:17we'll talk about one particular vendor
  173. 6:20of vpss um namely Amazon uh web services
  174. 6:24Amazon ec2 their elastic compute Cloud
  175. 6:27that essentially lets you self-service
  176. 6:29and spawn as many virtual machines as
  177. 6:31you want so long as you're willing to
  178. 6:33pay some number of cents per minute to
  179. 6:35have that virtual machine up and running
  180. 6:37and it's actually a wonderful way to uh
  181. 6:39plan for uh unexpected growth because
  182. 6:43you can even automate the process of
  183. 6:44spawning more web servers more database
  184. 6:46servers if you happen to suddenly get
  185. 6:48popular even overnight or because you've
  186. 6:50been slash dotted or posted on Reddit or
  187. 6:52the like and then you can have those
  188. 6:54machines automatically power off when
  189. 6:56interest in your product or website has
  190. 6:58started to subside all right so how
  191. 7:01suppose you are the fortunate sufferer
  192. 7:04of a good problem which is that your
  193. 7:05website all of a sudden is super super
  194. 7:07popular and this website has maybe some
  195. 7:09static web content HTML files gifs and
  196. 7:12the like Dynamic content like PHP code
  197. 7:15uh maybe even some database stuff maybe
  198. 7:18some uh database stuff like MySQL well
  199. 7:22how do you go about scaling your site so
  200. 7:24that it can handle more users well the
  201. 7:28most straightforward approach which is
  202. 7:29generally what's called vertical scaling
  203. 7:31vertical in the sense that well if
  204. 7:33you're running low on Ram or you're kind
  205. 7:35of exhausting your available CPU Cycles
  206. 7:38or you're running low on disk space
  207. 7:40what's the easiest most obvious solution
  208. 7:42to that
  209. 7:43problem AEL get a better processor and
  210. 7:46more RAM good get more RAM more
  211. 7:48processor more disk space and just throw
  212. 7:50resources or equivalently money at the
  213. 7:52problem unfortunately there is a catch
  214. 7:54here there's sort of a a seiling on what
  215. 7:57you can do why why is vertical scaling
  216. 8:00not necessarily a full solution well you
  217. 8:04can only upgrade one machine so much
  218. 8:06after a while you can't upgrade yeah
  219. 8:08exactly there's some real world
  220. 8:09constraints here where you can only buy
  221. 8:11a machine that's you know maybe 3
  222. 8:13gigahertz these days and maybe only has
  223. 8:16a few a handful of maybe a couple dozen
  224. 8:18CPUs or cores but at some point you're
  225. 8:22either going to exhaust your own
  226. 8:23financial resources or just the
  227. 8:25state-of-the-art in technology because
  228. 8:27just the world hasn't made a machine
  229. 8:29that has as many resources as you need
  230. 8:31so you need to get a little smarter but
  231. 8:33at least within here you have some
  232. 8:34discretion so in terms of CPUs these
  233. 8:37days most servers have at least two CPUs
  234. 8:41sometimes three or four or more and in
  235. 8:43turn each of those CPUs typically has
  236. 8:45multiple cores in fact most of the
  237. 8:46laptops you guys have here these days
  238. 8:48are generally at least dual core
  239. 8:51sometimes even quad core which means
  240. 8:53that you effectively have the equivalent
  241. 8:54of four CPUs or four brains inside of
  242. 8:57your computer even though they're all
  243. 8:58inside of the same chip essentially what
  244. 9:01does that mean concretely it means if
  245. 9:03you have a quad core machine you can
  246. 9:05your computer can literally do four
  247. 9:07things at once whereas in yesterday year
  248. 9:09when you had single core single CPU
  249. 9:11machines they could only do one thing at
  250. 9:13a time and even though we humans seem to
  251. 9:16think that you're simultaneously
  252. 9:18printing something you're pulling up a
  253. 9:19Google map you're getting email and all
  254. 9:21this stuff seems to be happening
  255. 9:22simultaneously the reality is the
  256. 9:24operating system is scheduling each of
  257. 9:26those programs to get just a Split
  258. 9:28Second of CPU time before giving another
  259. 9:31program then another program a split
  260. 9:33second of CPU time and we humans are
  261. 9:35just so slow relative to today's uh
  262. 9:37processors that we don't even notice
  263. 9:39that things are actually happening
  264. 9:40serially as opposed to uh in parallel
  265. 9:43but when you actually have quad core
  266. 9:45especially in a server that means
  267. 9:47whereas in yesterday year with a single
  268. 9:49core machine you could handle one web
  269. 9:51request at a time now for instance you
  270. 9:53could handle at least four at a time
  271. 9:55truly in parallel and even then a server
  272. 9:58will typically spawn what are called
  273. 9:59multiple processes or multiple threads
  274. 10:01so in reality you can at least give the
  275. 10:04impression that you're handling many
  276. 10:06more than even four requests per second
  277. 10:08so in short machines these days have
  278. 10:10gotten more and more and more CPUs as
  279. 10:13well as more cores and yet the funny
  280. 10:15thing here is that we humans also aren't
  281. 10:17very good at figuring out what to do
  282. 10:19with all of this available Hardware
  283. 10:21right most of you even if you have a
  284. 10:22dual core machine you don't really need
  285. 10:24a dual core machine to check your mail
  286. 10:26or to like write an essay for school
  287. 10:28right you were able to do that 5 10
  288. 10:29years ago with far fewer computational
  289. 10:31resources now In fairness there's bloat
  290. 10:34and software and Mac OS and windows and
  291. 10:36office are just getting bigger and
  292. 10:37bigger so we're using those resources
  293. 10:39but one of the really nice results of
  294. 10:43this trend toward more and more
  295. 10:44computational resources is that the
  296. 10:46world has been able all the more easily
  297. 10:48to start chopping up bigger servers into
  298. 10:51smaller vpss and indeed that's how
  299. 10:53Amazon and other Cloud providers so to
  300. 10:55speak uh are able to provide people with
  301. 10:57the self-service capability ility as
  302. 10:59we'll discuss a bit later so within
  303. 11:01these things there are few things you
  304. 11:03have discretion over uh if you've ever
  305. 11:05built a computer you might be familiar
  306. 11:07with uh parallel ATA or IDE or SATA or
  307. 11:12SAS anyone Axel what are these refer to
  308. 11:15yeah SATA has to do with hard drives
  309. 11:17okay good so SATA has to do with hard
  310. 11:19drives in fact all three of those have
  311. 11:20to do with hard drives years ago
  312. 11:22parallel ATA or IDE hard drives were
  313. 11:25very much in Vogue they you might still
  314. 11:27have them in older computers these days
  315. 11:29desktop computers uh pretty much but you
  316. 11:31wouldn't buy a new uh parallel ATA Drive
  317. 11:34these days instead you'd most likely get
  318. 11:35a SATA drive whether 3.5 in for a
  319. 11:38desktop or 2 and 1 12 in for a laptop
  320. 11:41and if you have servers or you have lots
  321. 11:44of money and a fancy desktop computer
  322. 11:46you can go with the SAS Drive um SAS is
  323. 11:49serial attached scuzzy and this really
  324. 11:52just boils down to faster for instance
  325. 11:54whereas parallel ATA and SATA drives
  326. 11:56typically ran at 7200 RPMs per minute uh
  327. 12:01revolutions per minute um SAS drives
  328. 12:03anyone know what they typically spin
  329. 12:06at and for those unfamiliar inside of a
  330. 12:09mechanical hard drive there is a one or
  331. 12:11more metal platters that literally spins
  332. 12:13much like an old school record player
  333. 12:16where the bits are now stored what what
  334. 12:19speed does a SAS Drive spin it's more
  335. 12:21than 7200 RPM Excell is it 15,000 uh
  336. 12:25yeah so 15,000 is where um they would
  337. 12:27typically perform sometimes 10,000 but
  338. 12:2915,000 so just twice as fast so that
  339. 12:31alone gives you a bit of a speed bump of
  340. 12:33course it comes at a price literally
  341. 12:35more money but that's one way of
  342. 12:37speeding things up so in oftentimes what
  343. 12:39people will do is for a given website
  344. 12:42that they're creating if it has a
  345. 12:43database databases tend to write to disk
  346. 12:46quite a bit right every Facebook update
  347. 12:48requires writing to disk and then
  348. 12:50reading back out some number of times so
  349. 12:52really where you might be touching disc
  350. 12:54a whole lot people can throw things like
  351. 12:56SAS drives um in their database so that
  352. 12:59their data can be read or written even
  353. 13:01more quickly and what's even faster than
  354. 13:04um mechanical drives these days Axel
  355. 13:07solid state drives yeah solid state
  356. 13:09drives ssds which have no moving parts
  357. 13:11and as a result electrically perform
  358. 13:13much better than mechanical drives but
  359. 13:15those two cost more money and they tend
  360. 13:17to be smaller in size so whereas you can
  361. 13:19buy like a 4 terabyte uh SATA drive
  362. 13:23these days 3 and 1/2 in for your desktop
  363. 13:25you can buy maximally a 768 G
  364. 13:29SSD these days for a lot more money
  365. 13:32typically all right
  366. 13:35so let's skip uh let's skip raid for now
  367. 13:41so horizontal scaling so this is in
  368. 13:43contrast with what we just discussed
  369. 13:44throwing money and throwing more of
  370. 13:46everything at a problem horizontal
  371. 13:48scaling is sort of accepting the fact
  372. 13:50that there's going to be the ceiling
  373. 13:51eventually so why don't we instead
  374. 13:53architect our system in such a way that
  375. 13:55we're not going to hit that rather we
  376. 13:57can kind of stay below loow it by even
  377. 14:00using not state-of-the-art hardware and
  378. 14:01the F most expensive stuff we can buy
  379. 14:03but cheaper Hardware servers that might
  380. 14:05be a few years old or at least are not
  381. 14:08uh the topof the line so that they'll be
  382. 14:10less expensive so rather than get few or
  383. 14:13one really good machine why don't we get
  384. 14:15a bunch of slower or at least cheaper
  385. 14:18machines instead plural number of
  386. 14:20machines so this is just a picture of a
  387. 14:22data center which is just meant to
  388. 14:23conure up the idea of scaling
  389. 14:25horizontally and actually using multiple
  390. 14:27servers to build out your topology but
  391. 14:30what does this actually mean well if you
  392. 14:34have a whole bunch of servers now
  393. 14:36instead of just one how what's the
  394. 14:39relationship now with lecture zero where
  395. 14:41we talked about HTTP and DNS right the
  396. 14:45world was very simple a few weeks ago
  397. 14:47when you had a server and it had an IP
  398. 14:49address and that IP address might have a
  399. 14:51domain name or host name associated with
  400. 14:53it and we told that story of what
  401. 14:54happens when you type in something.com
  402. 14:56enter on your laptop and you get back
  403. 14:58the pages on that single server but now
  404. 15:00we have a problem if we have a whole
  405. 15:02Isles worth of web servers Axel well
  406. 15:05you're going to have to have a
  407. 15:09way
  408. 15:13okayest okay good so now if we get an
  409. 15:15inbound HTTP request we somehow want to
  410. 15:18distribute that request over all of the
  411. 15:21various web servers that we might have
  412. 15:23whether it's two web servers or 200 the
  413. 15:25problem really is still the same if it's
  414. 15:27more than one we have to somehow figure
  415. 15:29that out so let me put up a fairly
  416. 15:32generic picture here let me flip fast
  417. 15:34those to this guy here so if we have a
  418. 15:37whole bunch of servers on the bottom
  419. 15:39here server one two dot dot dot and on
  420. 15:41the top we have some number of clients
  421. 15:43just random people on the internet we
  422. 15:45need to interpose now some kind of black
  423. 15:47box that's generally called a load
  424. 15:49balancer depicted here as a rectangle so
  425. 15:52that the traffic coming from people on
  426. 15:54the Internet is somehow distributed or
  427. 15:56balanced across our various backend
  428. 15:59servers so to speak so it might still be
  429. 16:02the case that server one and two and so
  430. 16:04forth have unique IP addresses but now
  431. 16:08when a user types in something.com and
  432. 16:10hit hits
  433. 16:12enter what IP address should we
  434. 16:15return how do we go about achieving the
  435. 16:18equivalent of this man in the middle who
  436. 16:20can somehow balance load across all in
  437. 16:23servers well let
  438. 16:26the return the IP addresses the load
  439. 16:29balancer send the request to the load
  440. 16:31balancer and then let the load balancer
  441. 16:34handle which computer send it to okay
  442. 16:36good so instead of in DNS returning the
  443. 16:39IP address of server one or server 2 or
  444. 16:41server dot dot dot you could instead
  445. 16:43return the equivalent of the IP address
  446. 16:44of this black box the load balancer and
  447. 16:47then let the load balancer figure out
  448. 16:49how to actually route data to those
  449. 16:52backend servers so that's actually
  450. 16:53pretty clean so now if the load balancer
  451. 16:55has a public IP address the backend
  452. 16:57server is now technically you don't even
  453. 16:59need public IP addresses they can
  454. 17:00instead have private addresses and what
  455. 17:03was the key distinction between public
  456. 17:04and private IPS back in lecture
  457. 17:09zero any anyone over here yeah Le the
  458. 17:13rest of the world see private exactly so
  459. 17:17the rest of the World by definition of
  460. 17:18private can't see private IP addresses
  461. 17:21then so that seems to have some nice uh
  462. 17:24privacy properties and that if no one
  463. 17:25else can see them they can't address
  464. 17:27them so those servers just by nature of
  465. 17:29this privacy can't be contacted at least
  466. 17:32directly by random adversaries bad guys
  467. 17:34on the internet so that's a plus
  468. 17:36moreover the world has been running out
  469. 17:38of uh version 4 IP addresses the 32-bit
  470. 17:41IP address has come into scarcity for
  471. 17:43some time now so it's just hard or
  472. 17:46sometimes expensive to get enough IP
  473. 17:48addresses to handle the various servers
  474. 17:50that you might buy so this alleviates
  475. 17:51that pressure now we need one IP and not
  476. 17:54multiple for our servers because we can
  477. 17:56give these backend servers like a a
  478. 17:58number like 192.168 which most of you
  479. 18:00have in your home routers probably or
  480. 18:0210. something or 17216 something all of
  481. 18:05those to Mark the start of a private IP
  482. 18:08address so that works all right so the
  483. 18:10load balancer has its own IP address now
  484. 18:12it gets a request from some client on
  485. 18:14the internet how using jargon from
  486. 18:17lecture zero onward can the load
  487. 18:19balancer decide or get that data to one
  488. 18:23of the backend servers how could we go
  489. 18:26about implementing that actually
  490. 18:28well you would probably first want to
  491. 18:30figure out which server to send it to so
  492. 18:32you want to check um if somebody has
  493. 18:35available CPU cycles that they're not
  494. 18:38using okay so and once you see that
  495. 18:40there's one server with enough CPU
  496. 18:42Cycles to handle that request s a local
  497. 18:44request the same request but locally
  498. 18:46inside your server Network okay to that
  499. 18:49machine um get back whatever it is that
  500. 18:52the client requested and then the load
  501. 18:54balance s excellent so this request
  502. 18:57arrives then at the load balance
  503. 18:58balancer the load balancer decides to
  504. 19:00whom he wants to send this packet server
  505. 19:02one or two or dot dot dot and you can
  506. 19:04make that decision based on any number
  507. 19:06of factor so Axel propose doing it based
  508. 19:08on load like who is the busiest versus
  509. 19:10the least busy odds are I should send my
  510. 19:13request to the least busy server in the
  511. 19:15interest of uh optimizing performance
  512. 19:18all around so let's assume that there's
  513. 19:20some way as Demar demarcated by those
  514. 19:22black arrows of like talking to those
  515. 19:24backend servers and saying hey how busy
  516. 19:25are you let me know so now the load
  517. 19:27balancer figures out it wants to send
  518. 19:29this particular request to server one so
  519. 19:31it sends that request to server one
  520. 19:33using similar mechanisms tcpip much like
  521. 19:36the packet how it traveled to the load
  522. 19:38balancer in the first place the server
  523. 19:39then gets the packet does its thing and
  524. 19:42says oh they want some HTML file here it
  525. 19:44is the response goes to the load
  526. 19:46balancer the load balancer then responds
  527. 19:48to the client and voila so that works
  528. 19:51what are some alternatives to load
  529. 19:53balancing based on the
  530. 19:56actual load on these server so load in
  531. 20:00general refers to how busy a server is
  532. 20:02so what's an even simpler approach than
  533. 20:04that because that frankly that sounds a
  534. 20:05little complex we've not talked at all
  535. 20:07about how one device can query another
  536. 20:09for uh characteristics like how busy are
  537. 20:11you even though it's possible
  538. 20:13Axel first let me point out inite that
  539. 20:16you need to have every file um every
  540. 20:18file the website has on every server so
  541. 20:21if you would instead uh say have one
  542. 20:23server containing all the HTML and one
  543. 20:26running and containing all the P you
  544. 20:29would then see well oh okay bad example
  545. 20:32one example one server with all the
  546. 20:34images and one with all the HTML client
  547. 20:36requests an image it sends it to the
  548. 20:38image server okay and if it's an HTML
  549. 20:41request to the HTML server okay good so
  550. 20:43the implication of the previous story
  551. 20:44that Axel told is that under this model
  552. 20:46server one two and so forth all need to
  553. 20:48be identical have the same content which
  554. 20:51is nice and that then it doesn't matter
  555. 20:53to whom you send the request the
  556. 20:54downside is now you're using n times
  557. 20:57this much dis space as you might
  558. 20:59otherwise need to but that's perhaps the
  559. 21:01price you pay for having this redundancy
  560. 21:03or to having this uh horizontal
  561. 21:05scalability or instead you could have
  562. 21:07dedicated servers these are for HTML
  563. 21:09these are for gifs these are for movie
  564. 21:11files and the like and you could do that
  565. 21:13just by having different URLs different
  566. 21:15host names this is for instance images.
  567. 21:18something.com this is videos.
  568. 21:20something.com and then the load balancer
  569. 21:22could take into account the host HTTP
  570. 21:25header to decide which direction it
  571. 21:27should go in so could work for us all
  572. 21:29right so what's an even simpler fistic
  573. 21:32than asking a backend server how busy
  574. 21:34are you right now like if you have no
  575. 21:36idea how to do that how instead could we
  576. 21:38balance load across an arbitrary number
  577. 21:40of
  578. 21:42servers think again back to lecture zero
  579. 21:45we can do all of this with only lecture
  580. 21:48zero under our
  581. 21:53belt so let's quickly tell the story I
  582. 21:55type in something.com into a browser I
  583. 21:57hit enter what
  584. 22:01happens Jack we create a packet to send
  585. 22:04okay packet to send to whom do we send
  586. 22:06it we send it to uh some place that will
  587. 22:09determine the IP address where we're
  588. 22:11sending it okay good something that will
  589. 22:12determine the IP address of where we're
  590. 22:14sending it to what's that thing called
  591. 22:16uh Isaac what's that called router uh
  592. 22:19not router routers get involved
  593. 22:22but DNS the DNS server domain name
  594. 22:25system server so that server in the
  595. 22:26world a whole bunch of of them that
  596. 22:29whose purpose in life is to translate
  597. 22:30host names to IPS and vice versa so I'm
  598. 22:34going to pause the story there that
  599. 22:36seems to be an opportunity now for us to
  600. 22:39return something yeah could you do some
  601. 22:43DNS tricks and return different IP
  602. 22:46addresses based on what the user
  603. 22:48requested good so this black box this
  604. 22:50load balance or maybe it's just a fancy
  605. 22:52DNS setup whereby instead of returning
  606. 22:54the IP address of the load balancer
  607. 22:56itself maybe in instead the DNS server
  608. 22:59just Returns the IP address of server
  609. 23:01one the first time someone asks for
  610. 23:03something.com and the next time someone
  611. 23:05requests something.com it Returns the IP
  612. 23:07address of server two followed by server
  613. 23:09three followed by dot dot dot and then
  614. 23:11wrapping around eventually to server one
  615. 23:13again so this is actually generally
  616. 23:14called round robin and you can do this
  617. 23:17fairly easily this is just a snippet of
  618. 23:19a popular DNS server called bind berley
  619. 23:22internet name uh name demon I believe is
  620. 23:26the D and this just suggests that if you
  621. 23:28want to have multiple IP addresses for a
  622. 23:30host name called dubdub duub you mention
  623. 23:33a which is denotes a record in just
  624. 23:35refers to an inp pointer here but a is
  625. 23:38the same as in lecture zero and then you
  626. 23:40just enumerate the IP address one after
  627. 23:42the other and by default this particular
  628. 23:45uh DNS server very popular one
  629. 23:48bind will return a different IP address
  630. 23:52for each request so that's nice it's
  631. 23:54simple again uses only some knowledge
  632. 23:56from lecture zero even though granted
  633. 23:58you have to know how to configure the
  634. 23:59DNS server but you don't need any fancy
  635. 24:01bidirectional communication with the
  636. 24:03backend servers in this model so that's
  637. 24:04nice but there's a price we pay for this
  638. 24:08Simplicity if we only do round robin
  639. 24:11where again we just spit out a different
  640. 24:13IP address each time and let me make
  641. 24:15this more concrete just so this isn't
  642. 24:17quite as abstract let me open up a
  643. 24:19terminal program here and do NS lookup
  644. 24:22for name server lookup of google.com
  645. 24:25this is exactly what Google does at
  646. 24:27least part their their load balancing
  647. 24:30solution is more sophisticated than this
  648. 24:32list suggests but indeed Google's DNS
  649. 24:35server returns multiple IP addresses
  650. 24:36each time so
  651. 24:39if this is so simple to implement what's
  652. 24:43the
  653. 24:45catch uh Axel well it's not a very smart
  654. 24:48solution
  655. 24:49because just there could be the case
  656. 24:52could be that one server gets all the
  657. 24:55really tough and hard requests that a
  658. 24:57lot processing power and the other ones
  659. 24:59just get the Fe the HTML files and
  660. 25:01there's no way to know that good so just
  661. 25:03by bad luck one of the servers could
  662. 25:05just get a really a real power user
  663. 25:08someone who's really doing something
  664. 25:10computationally difficult like I don't
  665. 25:12know uh what's a good examp sending lots
  666. 25:16of mail whereas someone else is just
  667. 25:17kind of logging in and poking around at
  668. 25:19a much slower rate and you we could come
  669. 25:21up with even more sophisticated examples
  670. 25:22than that but over time server one might
  671. 25:25just happen to get more heavyweight
  672. 25:28users than other servers so what's the
  673. 25:30implication well round robin is still
  674. 25:33going to keep sending more and more
  675. 25:35users to that server one nth of the time
  676. 25:38just by nature of round robin so that's
  677. 25:41not so good um what
  678. 25:44else causes
  679. 25:47problems here or what else breaks
  680. 25:53potentially so back to the lecture zero
  681. 25:56story I type something.com I hit enter
  682. 25:58my browser sends a request to the DNS
  683. 26:00server or my operating system sends a
  684. 26:02request to the DNS server gets the IP
  685. 26:04address and in this model it's the IP
  686. 26:06address of one of these servers then I
  687. 26:09send my packet as Jack proposed to that
  688. 26:11particular server get back a response
  689. 26:14stories ends but then a few seconds
  690. 26:16later I visit another link on
  691. 26:18something.com and hit enter which part
  692. 26:20of the story now
  693. 26:22changes Jack is it now going to send to
  694. 26:25the same server request do it send to a
  695. 26:28new server good
  696. 26:31question where it's coming from so what
  697. 26:34how does the story change and that'll
  698. 26:36give us the answer here Axel well it has
  699. 26:38to send it to
  700. 26:40Aver oh ideally yes so if you want a
  701. 26:43truly uniform distribution across all n
  702. 26:45servers then the DNS server has to
  703. 26:47return another response and I'd argue
  704. 26:48the DNS server will return a different
  705. 26:51response the next time it is queried but
  706. 26:54oh oh it's not queried why because it's
  707. 26:58saved or no but
  708. 27:01it's IP address
  709. 27:03isor Open Session it's it's really
  710. 27:06useless to query the DNS server for the
  711. 27:08same thing over and over again good so
  712. 27:09recall these caches back in lecture Z we
  713. 27:12talked about the implications of the
  714. 27:14good parts of caching whereby as ael's
  715. 27:16proposing there's no reason for Chrome
  716. 27:18or IE to send the same DNS request every
  717. 27:21single time you click a link on
  718. 27:23something.com that would just be a waste
  719. 27:24of time um you're going to lose some
  720. 27:26number of milliseconds every time time
  721. 27:27that happens or worse yet a second or
  722. 27:29two so instead your operating system
  723. 27:31typically caches these responses your
  724. 27:33browser typically caches these responses
  725. 27:36as well and so you just don't need to do
  726. 27:38those lookups so if you do happen to be
  727. 27:40that power user who's doing a heck of a
  728. 27:42lot of work of whatever sort on server
  729. 27:45one the next guy is going to be sent to
  730. 27:47server two not you with your subsequent
  731. 27:50requests so caching too can contribute
  732. 27:53to a disproportionate amount of load on
  733. 27:55certain servers largely and due to to
  734. 27:57bad luck indeed in DNS we didn't spend
  735. 28:00much time on this particular detail but
  736. 28:02there's typically expiration times ttls
  737. 28:04time to live values associated with an
  738. 28:07answer from a DNS server and that's
  739. 28:09typically an hour or five minutes or a
  740. 28:12day it totally depends on who controls
  741. 28:14the DNS server what that value is but
  742. 28:16that suggests too that if you are this
  743. 28:18power user on server one it might be a
  744. 28:20few minutes or hours or even days until
  745. 28:23you get assigned to some other server
  746. 28:26simply because you're TTL has expired by
  747. 28:29then so it's nice and simple we can do
  748. 28:31it with a simple configuration change
  749. 28:32but it doesn't necessarily solve all of
  750. 28:34our problems so in fact the approach
  751. 28:36Axel proposed first is actually pretty
  752. 28:39good whereby you don't use dns-based
  753. 28:41round robin rather a more sophisticated
  754. 28:44approach would be to let the load
  755. 28:45balancer decide to whom to send you in
  756. 28:48the back end and the load balancer can
  757. 28:49make that decision using any number of
  758. 28:51her istics it could even use round robin
  759. 28:54or Randomness because at that point you
  760. 28:56don't have to worry about caching issues
  761. 28:58because the DNS server has only returned
  762. 29:00one IP so but that still leads you to
  763. 29:02the risk that you'll be putting too much
  764. 29:04load on some server so we could take for
  765. 29:06instance server load into account at
  766. 29:08that point but there is something else
  767. 29:10that breaks if we fast forward
  768. 29:11mid-semester to when we started talking
  769. 29:13about cookies and
  770. 29:16HTTP and sessions in
  771. 29:19PHP to spark discussion I propose that
  772. 29:23sessions have just broken in PHP if our
  773. 29:26backend servers are PHP based
  774. 29:30websites and they are using the session
  775. 29:33super Global load balancing seems to
  776. 29:36break this model why Jack because now
  777. 29:39the different different servers have
  778. 29:41different people sessions so Al one
  779. 29:43might have my session if I then am
  780. 29:46redirected from server one to server two
  781. 29:49server two might not have my session
  782. 29:51exactly so sessions recall tend to be
  783. 29:54specific to the given machine we saw
  784. 29:56examples involving sltm which is a
  785. 29:58temporary directory on a Linux system
  786. 30:00where sessions are typically saved as uh
  787. 30:02text files serialized text files so that
  788. 30:05means though that your session might be
  789. 30:06sitting on the hard drive of server one
  790. 30:08and yet if by a random chance you are
  791. 30:10sent via round robin into server two or
  792. 30:12server three instead of server one in
  793. 30:15the worst case you're going to see the
  794. 30:16same website but you're going to be told
  795. 30:18to log in again for instance because
  796. 30:20that Server doesn't know that you've
  797. 30:21logged in more okay fine you kind of
  798. 30:23bite your tongue and you type in your
  799. 30:25username and password again and hit
  800. 30:26enter and suppose you're a really good
  801. 30:29sport and you do this for all end
  802. 30:30servers you have no idea why
  803. 30:32something.com keeps prompting you to log
  804. 30:34in but eventually you will have a
  805. 30:35session cookie on all of those servers
  806. 30:37the catch then though is that if
  807. 30:39something.com is an e-commerce site and
  808. 30:41you're adding things to your shopping
  809. 30:42cart now you literally have put a book
  810. 30:44in your cart over here a different book
  811. 30:46in this card a different book in this
  812. 30:48card and when you check out you can't
  813. 30:49check out the Aggregates so this is a
  814. 30:52very non-trivial problem now Axel um but
  815. 30:56this wouldn't happen if you
  816. 30:57if you had dedicated machines
  817. 30:59Distributing dedicated files one machine
  818. 31:01running PHP and then one maching all the
  819. 31:04images very true so if we have
  820. 31:06horizontally scaled in the sense that we
  821. 31:08factored out disparate services this is
  822. 31:10our PHP server this is our uh GIF server
  823. 31:13this is our video server then indeed
  824. 31:15this problem would not arise because
  825. 31:16presumably all the the PHP traffic would
  826. 31:19get routed to the PHP server but an
  827. 31:21obvious push back to that solution is
  828. 31:24what you're Isaac well if one of them
  829. 31:27crashes you lose all images okay good so
  830. 31:31there's no redundancy which is not good
  831. 31:33for uptime if anything breaks Axel and
  832. 31:35also well at some point in time if you
  833. 31:39get popular enough that one PHP server
  834. 31:41is not going to be able to handle
  835. 31:42everything
  836. 31:43good then the story is the same as soon
  837. 31:45as you get popular you have too much
  838. 31:47load for a single PHP server then we
  839. 31:49have to solve this problem anyway so how
  840. 31:52do we go about solving this problem this
  841. 31:54seems to be a real pain this one
  842. 31:58and to be clear the problem now is that
  843. 31:59in as much as sessions are typically
  844. 32:02implemented per server in the form of
  845. 32:04like a text file like we saw in sltm
  846. 32:08then you can't really use round robin
  847. 32:10you can't really use loow true load
  848. 32:13balancing taking into account each
  849. 32:14server's load because you need to make
  850. 32:16sure that Alice if she's initially sent
  851. 32:18to server one subsequently gets sent to
  852. 32:20server one again and again and again for
  853. 32:23at least you know an hour or a day or
  854. 32:25some amount of time so that her is
  855. 32:27useful
  856. 32:34Jack started there and excellent yes so
  857. 32:37absolutely we could just continue this
  858. 32:39idea of factorization and factor out not
  859. 32:42the various types of files but a service
  860. 32:45like session States so if we instead had
  861. 32:47a file server you know like a big
  862. 32:49external hard drive so to speak that is
  863. 32:52connected to all of the servers one and
  864. 32:54two and three so that anytime they store
  865. 32:57session data they store it there instead
  866. 33:00of on their own hard drive then this way
  867. 33:02we could share state so indeed that
  868. 33:04could be a solution here
  869. 33:06Axel I I don't know if a load balancer
  870. 33:09has that function but maybe the instead
  871. 33:11of having an extra server that all the
  872. 33:13other servers need query load balancer
  873. 33:16because all traffic goes through that
  874. 33:17anyhow but if the load balancer session
  875. 33:20okay so that's not bad at all so we
  876. 33:22already have a man in the middle here
  877. 33:23it's a black box but there's no reason
  878. 33:25it couldn't be a server with hard dis
  879. 33:27so want to put the sessions on the load
  880. 33:29balancer that could absolutely work so
  881. 33:31let me be difficult then and whether we
  882. 33:33put the sessions in the load balancer or
  883. 33:35whatever that it's no longer a load
  884. 33:36balancer then it's obviously doing more
  885. 33:38it's more of a a server that happens to
  886. 33:40be balancing load and storing sessions
  887. 33:42whether we put sessions there in that
  888. 33:44black box or elsewhere in a new box on
  889. 33:46the screen we seem to have introduced uh
  890. 33:51weakness now in our Network topology
  891. 33:54because what if that machine breaks
  892. 33:57it would seem to be the case that even
  893. 33:59though we have n servers which in theory
  894. 34:01those guys are never all going to die at
  895. 34:03once assuming that it's not the power
  896. 34:05electricity or something stupid like
  897. 34:06that that's somehow related to all of
  898. 34:08them but odds are they're not all just
  899. 34:10going to up and die simultaneously so we
  900. 34:12have really good redundancy in our
  901. 34:14server model right now but as soon as we
  902. 34:15introduce just a database or file server
  903. 34:18for our sessions if that guy dies then
  904. 34:21what was the point of spending all this
  905. 34:23money on all these backend servers our
  906. 34:25whole site goes down because we have no
  907. 34:27ability to remember that people are
  908. 34:28logged in if we can't remember they're
  909. 34:29logged in no one can buy anything so how
  910. 34:31do we fix that problem so we've solved
  911. 34:33one problem but if you think of that
  912. 34:35sort of old uh visual where you have
  913. 34:38like a garden hose with lots of leaks in
  914. 34:39it and you plug one of them with one
  915. 34:41hand all of a sudden a new leak Springs
  916. 34:43up elsewhere that's kind of what's
  917. 34:44happened here we've solved the problem
  918. 34:46of shared state but now we've sacrificed
  919. 34:50some uh some robustness some redundancy
  920. 34:54how do we now fix the
  921. 34:55ladder
  922. 35:03Exel probably not
  923. 35:14the okay good so we could just use a
  924. 35:17sort of different approach to storing
  925. 35:19our data and rather than just store it
  926. 35:21on the hard disk as usual we could use
  927. 35:23something called raid so actually this
  928. 35:24is a good way to tie in the thing we
  929. 35:26skipped over a moment ago let me just
  930. 35:29pull up something to write on
  931. 35:31here
  932. 35:35uh
  933. 35:37so redundant array of independent discs
  934. 35:40is a technology more succinctly known as
  935. 35:43raid raid can actually be used in
  936. 35:44desktop computers these days um even
  937. 35:47though it's not all that common some
  938. 35:48companies like Dell and apple make it
  939. 35:51relatively easy to use Raid on your
  940. 35:53system and what does this mean well raid
  941. 35:55can come in a few different forms
  942. 35:56there's something called raid zero
  943. 35:58there's something called raid 1 there's
  944. 36:00something called raid five there's
  945. 36:02something called raid six there's
  946. 36:03something called RAID 10 and there's
  947. 36:05even more but these are some of the
  948. 36:07simplest ones to talk about so all of
  949. 36:09these techn all of these variants of
  950. 36:12raid assume that you have multiple hard
  951. 36:14drives in your computer for different
  952. 36:16purposes potentially so in the world of
  953. 36:18raid one of raid zero you typically have
  954. 36:21uh two hard drives that are of identical
  955. 36:23size terabyte 2 terabytes 512 me G
  956. 36:27whatever it is two identical hard drives
  957. 36:30and you do what's called stripe data
  958. 36:32across them whereby every time the
  959. 36:35operating system wants to save a file
  960. 36:36especially big files it will first write
  961. 36:39to this drive a bit then to this one
  962. 36:41then to this one then to this one the
  963. 36:43motivation being these hard drives are
  964. 36:44typically large and mechanical with
  965. 36:46spinning platters like we discussed
  966. 36:48earlier and so it might take this guy a
  967. 36:50little while to write out some number of
  968. 36:53bits now it's going to be split second
  969. 36:54in reality but that's a split second we
  970. 36:56don't really have when we're trying to
  971. 36:57service lots of users so striping allows
  972. 37:00me to write some data here then here
  973. 37:02then here then here then here then here
  974. 37:04effectively doubling the speed at which
  975. 37:06I can write files especially large ones
  976. 37:07to diss so raid zero is nice for
  977. 37:10performance however raid one gives you a
  978. 37:12very different property with raid one
  979. 37:14you still have two hard drives but you
  980. 37:16mirror data so to speak across them so
  981. 37:19that anytime you write out a file you
  982. 37:21store it both places simultaneously
  983. 37:24there's a bit of performance overhead to
  984. 37:25writing it in two places albe it in
  985. 37:27parallel but the upside now is that
  986. 37:30either of these drives can die and your
  987. 37:32data is still perfectly intact and it's
  988. 37:34actually an amazing technology because
  989. 37:37if even if you just have this in your
  990. 37:38desktop computer you have two drives one
  991. 37:40of them dies just because of bad luck it
  992. 37:42was there was a defect or it's multiple
  993. 37:44years old and it just upped and died so
  994. 37:46long as the other one is still working
  995. 37:47the theory behind raid is that you can
  996. 37:49then run to the store buy another hard
  997. 37:51drive that's at the same size or bigger
  998. 37:54plug it into your computer boot back up
  999. 37:57and most typically automatically The
  1000. 38:00Raid array will rebuild itself whereby
  1001. 38:03all of the data that's on the remaining
  1002. 38:05drive will copy itself automatically
  1003. 38:07over to the new one and after a few
  1004. 38:08minutes or hours you're back to a safer
  1005. 38:11place whereby now even the other Drive
  1006. 38:13can up and die sometimes you have to run
  1007. 38:15a command or choose a menu option to
  1008. 38:16induce that but typically it's automatic
  1009. 38:18you can do it even sometimes in some
  1010. 38:20machines while the computer's still on
  1011. 38:22so you don't even have to suffer any
  1012. 38:23downtime so that's great RAID 10 is a
  1013. 38:26essentially the combination of those two
  1014. 38:27you typically use four drives and you
  1015. 38:29have both striping and redundancy so you
  1016. 38:32sort of get the best of both worlds but
  1017. 38:33costs you twice as much because you need
  1018. 38:35twice as many hard diss raid five and
  1019. 38:37raid six are kind of nice middle grounds
  1020. 38:40with raid one uh or nice variants of
  1021. 38:42raid one whereby raid one's kind of
  1022. 38:43pricey right rather than buy two one
  1023. 38:46hard drive I literally have to spend
  1024. 38:48twice as much and get two hard drives
  1025. 38:50raid five is a little more versatile
  1026. 38:53whereby I typically have say three
  1027. 38:55drives four drives five drives but only
  1028. 38:58one of them is used for redundancy so if
  1029. 39:00I get five 1 tbte drives I have four
  1030. 39:04terabytes of usable space so I'm only
  1031. 39:07sacrificing oneth in that case of my
  1032. 39:10available disc capacity whereas in raid
  1033. 39:12one you're sacrificing one one over one
  1034. 39:14half so 50% of it so raid five you just
  1035. 39:17get better economy of scale whereby you
  1036. 39:19can grow bigger and you still have some
  1037. 39:22redundancy so in raid five if you have
  1038. 39:24three or four or five hard drives in in
  1039. 39:26the array one of them can die any of
  1040. 39:28them you run to the store put in a new
  1041. 39:30one and you haven't lost any data raid
  1042. 39:33six is even better what does raid six do
  1043. 39:36do you think Axel I think two drives can
  1044. 39:38die exactly in raid six any two drives
  1045. 39:41can die you still won't have lost any
  1046. 39:43data and so long as you run to the store
  1047. 39:44fast enough and put in one or both
  1048. 39:46drives again you'll be good to go of
  1049. 39:48course the price you pay with rate six
  1050. 39:50is literally another hard drive but at
  1051. 39:51least now you can maybe sleep a bit
  1052. 39:53better at night knowing that man two of
  1053. 39:55my hard drives has to die before I have
  1054. 39:57to really worry about this so these are
  1055. 40:00really nice Technologies and so as Axel
  1056. 40:02proposes here the upside of using
  1057. 40:04something like that in whatever uh file
  1058. 40:07server we're storing our shared sessions
  1059. 40:09is we can at least decrease the
  1060. 40:10probability of downtime at least related
  1061. 40:12to hard diss unfortunately it still has
  1062. 40:16a power cord that someone could trip
  1063. 40:17over or the power supply could die it
  1064. 40:19still has Ram that could go on the fritz
  1065. 40:21a motherboard that could die any number
  1066. 40:23of things could still happen but at
  1067. 40:25least we can throw redundant inside of
  1068. 40:27the confines of a single server and this
  1069. 40:29can definitely help with our uptime and
  1070. 40:31with our robustness and indeed with
  1071. 40:33actual servers that you would buy for a
  1072. 40:35data center not so much the home it's
  1073. 40:38very common for computers to have not
  1074. 40:40only multiple hard drives and lots of uh
  1075. 40:43multiple Banks of RAM and they would
  1076. 40:45often have multiple power supplies as
  1077. 40:48well and it's actually a really cool
  1078. 40:49technology there too if one of your
  1079. 40:50power supplies dies you can literally
  1080. 40:52pull it out the machine keeps running
  1081. 40:54you put in a new one and then it spreads
  1082. 40:56the amperage across two power supplies
  1083. 40:59once both are back up and running all
  1084. 41:01very hot swappable amazing technology
  1085. 41:03these days and as an aside if you still
  1086. 41:04own a desktop computer there is no
  1087. 41:06reason you shouldn't use Raid these days
  1088. 41:08it is just very good practice since it
  1089. 41:10will uh allow you to avoid downtime and
  1090. 41:13data loss with higher
  1091. 41:15probability okay but someone tripped
  1092. 41:18over the power cord someone tripped over
  1093. 41:20both power cords in the case of
  1094. 41:22redundant power suppli so axle solution
  1095. 41:24and even mine with redundant power
  1096. 41:25supply hasn't solved the problem of
  1097. 41:28shared storage becoming all of a sudden
  1098. 41:31a single point of failure so what else
  1099. 41:33could we do to still get the property of
  1100. 41:37shared state so it doesn't matter what
  1101. 41:39backend server I end up on but I instead
  1102. 41:42get I still get the ability to suffer
  1103. 41:46some downtime well shared storage is can
  1104. 41:48to come in a bunch of different ways so
  1105. 41:50we talked really about things as a file
  1106. 41:51server but this can be incarnated with
  1107. 41:53very specific Technologies and just to
  1108. 41:55Rattle them off even though we won't
  1109. 41:56talk about them in much technical detail
  1110. 41:58fiber channel FC is a very fast very
  1111. 42:01expensive technology that you can use in
  1112. 42:04offices and data centers not so much the
  1113. 42:06home to provide very fast shared storage
  1114. 42:08across servers so that's just one type
  1115. 42:10of file server if you will um I scuzzy
  1116. 42:13is another technology that uses uh IP
  1117. 42:16Internet Protocol and uses ethernet
  1118. 42:18cables to exchange data with servers so
  1119. 42:20that's a nice somewhat cheaper way of
  1120. 42:22exchange of having a shared file server
  1121. 42:25that um uh that can be used by multiple
  1122. 42:29actually in the case of iuz you
  1123. 42:30typically use it with single servers um
  1124. 42:33so let me retract that that is not a
  1125. 42:34solution to our current cookie problem
  1126. 42:36um but what about MySQL right we use
  1127. 42:38that for a couple weeks MySQL seems to
  1128. 42:42be a nice candidate because it's already
  1129. 42:43a separate server potentially could not
  1130. 42:46the backend servers just write their
  1131. 42:48session objects to a database they
  1132. 42:51definitely could so just because you're
  1133. 42:53storing things in a just because we
  1134. 42:56usually store things like user data and
  1135. 42:58user generated data in a database
  1136. 43:00doesn't mean we can't store metadata
  1137. 43:01like our cookie information as well or
  1138. 43:04that too comes from users though NFS
  1139. 43:06Network file system this is just a
  1140. 43:07protocol that you can use to implement
  1141. 43:10the idea that Axel proposed of a shared
  1142. 43:12file system it just means you've got one
  1143. 43:14server and you're exposing your hard
  1144. 43:16disk to multiple other computers but
  1145. 43:18again we haven't really solved the
  1146. 43:20problem of share of downtime so what's
  1147. 43:24the most obvious way of mitigating the
  1148. 43:27risk that your single file server will
  1149. 43:29go
  1150. 43:31down Axel keep the cop of session loc
  1151. 43:35good right if it's not if you don't have
  1152. 43:38um if you're worried about the one file
  1153. 43:40server going down well the obvious
  1154. 43:41solution even though money um and some
  1155. 43:44technical complexity will just get two
  1156. 43:46now somehow you have to figure out how
  1157. 43:47to sync the two so that one has a copy
  1158. 43:51of the other's data and vice versa so
  1159. 43:53let's actually come back to that issue
  1160. 43:55it's generally known as rep application
  1161. 43:56but it is something we can potentially
  1162. 43:59achieve but before we segue to um
  1163. 44:05distribution of things let's finish out
  1164. 44:08this load balancer question so how do
  1165. 44:10you go about implementing this black box
  1166. 44:12well these days you actually have a
  1167. 44:13bunch of options um in software you can
  1168. 44:16do things relatively easily with a
  1169. 44:17browser pointing and clicking using
  1170. 44:20things like Amazon's elastic load
  1171. 44:21balancer a scenario for which we'll talk
  1172. 44:23about a bit later ha proxy High
  1173. 44:26availability proxy is free open source
  1174. 44:28software that you can run on a server
  1175. 44:30that can do load balancing as well using
  1176. 44:31any either of the heris stics we
  1177. 44:33discussed earlier round robin or
  1178. 44:35actually taking load into account
  1179. 44:36somehow um Linux virtual server LVS is
  1180. 44:39another free software a piece of
  1181. 44:41software you can use and then in the
  1182. 44:42world of Hardware people have made big
  1183. 44:44business out of load balancers Barracuda
  1184. 44:47Cisco Citrix F5 are some of the most
  1185. 44:49popular vendors here um most of whom are
  1186. 44:51atrociously overpriced for what they do
  1187. 44:54so case in point like Citrix is a
  1188. 44:57popular company that sells load
  1189. 44:58balancers take a guess as to what a load
  1190. 45:01balancer might cost you these days it's
  1191. 45:02a highly variable range but there's
  1192. 45:04different models but take a guess how
  1193. 45:07much did that black bux cost Isaac in
  1194. 45:09the thousands definitely in the
  1195. 45:11thousands
  1196. 45:14indeed in fact we have a small one so to
  1197. 45:17speak on a small one relatively speaking
  1198. 45:19on campus that was
  1199. 45:22$220,000 and guess what that one's cheap
  1200. 45:27so you can literally spend on these
  1201. 45:28kinds of things granted not this is this
  1202. 45:30is not what the costs that await you
  1203. 45:31right after the semester ends today um
  1204. 45:34but $100,000 for a load balancer or even
  1205. 45:37generally a pair of load balancers so
  1206. 45:39that either of them can die and the
  1207. 45:41other one can stay alive so in the world
  1208. 45:43of Enterprise Hardware these ideas we're
  1209. 45:45talking about are ridiculously priced
  1210. 45:47typically because of support contracts
  1211. 45:49and the like so just realize software is
  1212. 45:51number one on the list because there are
  1213. 45:53other ways to achieve this much more
  1214. 45:55inexpensive indeed for years um one of
  1215. 45:57the courses I teach we used ha proxy to
  1216. 46:00balance load because it was so
  1217. 46:02relatively easy to set up and 100% free
  1218. 46:04so realize these same ideas can be both
  1219. 46:06bought and set up uh on your own quite
  1220. 46:10readily these days all right um let's
  1221. 46:15pause here and when we come back we'll
  1222. 46:16take a look at some issues of like
  1223. 46:18caching of replication in databases and
  1224. 46:20also how we can speed up PHP a bit let's
  1225. 46:22take our five minute break
  1226. 46:24here
  1227. 46:27all right we are back and I almost
  1228. 46:29forgot we have one other solution to
  1229. 46:31this problem of the need for sticky
  1230. 46:33sessions sticky sessions meaning that
  1231. 46:36when you visit a website multiple times
  1232. 46:39your session is somehow preserved even
  1233. 46:42if there are multiple backend servers so
  1234. 46:45shared storage was the idea we really
  1235. 46:47vetted quite a bit and we didn't quite
  1236. 46:49get to a perfect solution since even
  1237. 46:52though we factored out the storage and
  1238. 46:55and put everyone's cookies or session
  1239. 46:57objects on the same server we feels like
  1240. 46:59we need some redundancy but we'll come
  1241. 47:01back to that in the context of MySQL in
  1242. 47:03just a bit but what about cookies I
  1243. 47:05propose that cookies themselves could
  1244. 47:09offer a solution to the problem of
  1245. 47:12sticky sessions and again Sticky session
  1246. 47:14means even if you visit a website
  1247. 47:17multiple times you're still going to end
  1248. 47:19up with the same session object or more
  1249. 47:21specifically you're still going to end
  1250. 47:22up on the same backend server
  1251. 47:33Axel which server you want to go to in a
  1252. 47:36cie
  1253. 47:38okay store everything in cookies but
  1254. 47:40that's that's store okay yeah so storing
  1255. 47:43everything in cookie is probably bad
  1256. 47:45because one then it's really starting to
  1257. 47:47violate privacy because rather than
  1258. 47:48store a big key you're going to store
  1259. 47:50like the isbns of all of the books in
  1260. 47:52your shopping cart and that might be
  1261. 47:53fine but feels like your roommates and
  1262. 47:55family members don't don't need to know
  1263. 47:56what is in your cookies moreover cookies
  1264. 47:58typically have a finite size of a few
  1265. 48:01kilobytes so there's definitely going to
  1266. 48:02be circumstances in which you just can't
  1267. 48:03fit everything you want to in the cookie
  1268. 48:05so you know an interesting idea but
  1269. 48:07probably not the best so you could store
  1270. 48:09the ID of the server in a cookie so that
  1271. 48:12the user the second and third and fourth
  1272. 48:14times they visit your website as by
  1273. 48:16following links or coming back some
  1274. 48:19other time they are going to present the
  1275. 48:22equivalent of a hand stamp saying hey I
  1276. 48:24was on backend server one send me there
  1277. 48:27again so that's a pretty nice idea there
  1278. 48:29is one at least one downside here what
  1279. 48:32do you like what do you not like
  1280. 48:34potentially about this idea of storing
  1281. 48:35in a cookie that gets put on the user's
  1282. 48:38browser that they subsequently transmit
  1283. 48:40back to you the number of or the ID of
  1284. 48:42the server to which they should be
  1285. 48:47sent maxel well for one expiration
  1286. 48:50expiration in what sense well cookie
  1287. 48:53expires Okay so eventually cookie is
  1288. 48:56going to expire though we saw a couple
  1289. 48:58lectures ago we could make it expire in
  1290. 49:0110 years if we really wanted to and
  1291. 49:03frankly we're never going to avoid that
  1292. 49:05even if we had a single server cookies
  1293. 49:06could eventually expire so at least
  1294. 49:08that's not a new problem so I'm not too
  1295. 49:09worried about expiration now because
  1296. 49:12that's not a problem new to us simply
  1297. 49:15because of load
  1298. 49:18balancing does anything not feel right
  1299. 49:21about storing the ID of the server in
  1300. 49:23the
  1301. 49:24cookie
  1302. 49:32yeah so if we just put like the backend
  1303. 49:34IP so the private IP address in the
  1304. 49:36cookie you know what if the IP changes
  1305. 49:38what if that uh what if the IP changes
  1306. 49:40so that's a little problematic and it's
  1307. 49:42also one of these principled things like
  1308. 49:44you don't really need to reveal to the
  1309. 49:46world what your IP address scheme is
  1310. 49:48it's not necessarily something they
  1311. 49:50could exploit but it's just the whole
  1312. 49:52world doesn't need to know that moreover
  1313. 49:54we can implement the same idea by still
  1314. 49:56storing a cookie on the user's computer
  1315. 49:57but why don't we take the PHP approach
  1316. 49:59of let's just store a big random number
  1317. 50:01and then have the load balancer remember
  1318. 50:03that that big random number belongs to
  1319. 50:05server one and this other big random
  1320. 50:07number belongs to server two and so
  1321. 50:10forth so a little more work on the load
  1322. 50:11balancer but in this way then we're
  1323. 50:13really not putting any state that might
  1324. 50:17change or might be a little privacy
  1325. 50:19revealing on the actual user's computer
  1326. 50:21moreover we also take away the ability
  1327. 50:23for them to spoof that cookie
  1328. 50:26just to get access to some other server
  1329. 50:28now whether or not they could do
  1330. 50:29anything with that uh trick is unclear
  1331. 50:31but at least we take the bill away that
  1332. 50:33ability Al together so there's no
  1333. 50:35surprises all right so cookies indeed
  1334. 50:37are something that these black boxes of
  1335. 50:39load balancers tend to do whereby you
  1336. 50:41can configure them to insert a cookie
  1337. 50:43themselves it doesn't just have to be a
  1338. 50:45back-end web server that generates
  1339. 50:46cookies the load balancer similarly
  1340. 50:49could be inserting a cookie with the set
  1341. 50:51cookie header that the end user then
  1342. 50:54subsequently sends back so that we can
  1343. 50:56remember what backend server to send the
  1344. 50:58user to now if the user has cookies
  1345. 51:00disabled well then this whole system
  1346. 51:02breaks down but again so does a lot of
  1347. 51:04functionality we've discussed thus far
  1348. 51:06this semester but there are sometimes
  1349. 51:08some workarounds so a word on PHP PHP
  1350. 51:12and interpreted languages in general
  1351. 51:13tend to get a bad WAP for performance
  1352. 51:15because they tend not to be as high
  1353. 51:17performing as a compiled language like
  1354. 51:18C++ or C or the like however there are
  1355. 51:22some ways to mitigate this there's this
  1356. 51:23notion of PHP acceleration
  1357. 51:26whereby you can run a PHP program The
  1358. 51:29Source Code Through php.exe The
  1359. 51:32Interpreter on the system and it turns
  1360. 51:34out that PHP does typically compile that
  1361. 51:37file in a sense down to something that's
  1362. 51:39more efficiently executed much like Java
  1363. 51:41compile something down to something
  1364. 51:42called bik code but you typically PHP
  1365. 51:46throws the results of that compilation
  1366. 51:49away whereby it does it again and again
  1367. 51:52for every subsequent request however
  1368. 51:54with very simple
  1369. 51:56uh with relatively straightforward and
  1370. 51:58freely available software you can
  1371. 52:00install a PHP accelerator here are just
  1372. 52:03four possibilities that essentially
  1373. 52:05eliminate that discarding of the PHP op
  1374. 52:09codes and instead keep them around so
  1375. 52:11another words the first time someone
  1376. 52:12visits your site the PHP file is going
  1377. 52:14to be interpreted and some op codes for
  1378. 52:16performance generated but they're not
  1379. 52:19going to be thrown away because the next
  1380. 52:21time you or someone else visits the site
  1381. 52:23that PHP file is not going to have to be
  1382. 52:24rep first and reinterpreted the op codes
  1383. 52:27are just going to be executed so you get
  1384. 52:28the benefit of some added performance
  1385. 52:30now the only gotcha is if you ever
  1386. 52:32change any of your. PHP files you have
  1387. 52:35to uh throw away the cached op codes but
  1388. 52:40uh these various tools typically do that
  1389. 52:42for you python has a similar mechanism
  1390. 52:44where you'll get py files or your source
  1391. 52:46code files but pyc files are the
  1392. 52:49compiled versions that can be executed
  1393. 52:51more quickly so the same idea as at play
  1394. 52:54here so this is one of the these things
  1395. 52:55that is relatively easy and free to
  1396. 52:58enable and gives you all the more
  1397. 53:00performance specifically the ability to
  1398. 53:02handle all the more requests per second
  1399. 53:04in the context of a PHP based website so
  1400. 53:07what about caching too caching in
  1401. 53:09general is a great thing it solved some
  1402. 53:10of our DNS concerns early on but it
  1403. 53:12introduced it others because caching can
  1404. 53:15be a bad thing if some uh value has
  1405. 53:17changed but you have the old one but
  1406. 53:19caching can be implemented in the
  1407. 53:21context of dynamic websites in a few
  1408. 53:23different ways so I propose that through
  1409. 53:25HTML through MySQL and through something
  1410. 53:27called MCD we can achieve some caching
  1411. 53:30benefits here so this is a screenshot of
  1412. 53:33one of the most 1990s websites out there
  1413. 53:36and this was not even taken in the 1990s
  1414. 53:38this was taken a couple years ago and I
  1415. 53:40just visited out of curiosity Craigslist
  1416. 53:41today still looks the same so what's
  1417. 53:44interesting about Craigslist though is
  1418. 53:46that it is a dynamic website and that
  1419. 53:48you can fill out a form and post a for
  1420. 53:50sale ad or a roommate ad or the like and
  1421. 53:53the website does actually change but
  1422. 53:55it's if we zoom in on this and it's
  1423. 53:57going to be a little blurry because of
  1424. 53:58the screenshot the URL that's up there
  1425. 54:01is actually do HTML even though it's
  1426. 54:04barely readable at this resolution which
  1427. 54:07is to suggests that Craigslist is
  1428. 54:09apparently accepting user input through
  1429. 54:11forms for instance whoever uh wrote up
  1430. 54:14this uh job advertisement some time ago
  1431. 54:17but then Craigslist is spitting it out
  1432. 54:19as a HTML file as opposed to storing it
  1433. 54:24where or in
  1434. 54:27what
  1435. 54:34Axel yeah so this is in stark contrast
  1436. 54:36to what we've done for project zero
  1437. 54:39project one using PHP as the back end
  1438. 54:41whereby you store data like this like
  1439. 54:43server side in maybe an XML file or more
  1440. 54:46realistically in an in a mySQL database
  1441. 54:48or similar and then you generate a page
  1442. 54:50like this dynamically so why is
  1443. 54:53Craigslist doing this apparently
  1444. 54:56could just be they're stuck in the 90s
  1445. 54:58but there's a compelling reason too AEL
  1446. 55:01well if they store the actual HTML file
  1447. 55:03then they don't have to regenerate it
  1448. 55:06every time it's visited yeah exactly if
  1449. 55:08they're storing the HTML file they just
  1450. 55:09don't have to regenerate it every time
  1451. 55:11it's Revisited so this itself is caching
  1452. 55:14it's not caching in any particularly
  1453. 55:15fancy way you're just generating the
  1454. 55:17HTML and saving it something called like
  1455. 55:19something. HTML and storing it on dis
  1456. 55:22and the upside of this is that web
  1457. 55:23servers like Apache are really really
  1458. 55:25really good and fast at just spitting
  1459. 55:27out bits just spitting out raw static
  1460. 55:30content like a gif a JPEG an HTML file
  1461. 55:33right the performance optimizations
  1462. 55:34these days generally relate to the
  1463. 55:36languages like PHP and Python and Ruby
  1464. 55:39where you're trying to fine-tune
  1465. 55:40Performance but if all you have to do is
  1466. 55:42respond to a tcpi tcpip request with a
  1467. 55:45bunch of bites from dis that's
  1468. 55:46relatively straightforward these days
  1469. 55:48and so they're taking advantage of the
  1470. 55:50performance presumably of serving up
  1471. 55:52static content but this comes at a cost
  1472. 55:55what's the downside of this file based
  1473. 55:58caching
  1474. 56:02approach someone
  1475. 56:05else nothing we've done thus far is sort
  1476. 56:08of a complete win there's always a
  1477. 56:10gotcha Lou space okay so space so we're
  1478. 56:14storing it on disk and you know if
  1479. 56:16you've ever posted on Craigslist they're
  1480. 56:18also storing it somewhere in a database
  1481. 56:20because they do let you go back and edit
  1482. 56:22it it's just Craigslist is one of these
  1483. 56:25where reads are probably much more
  1484. 56:27common than writes indeed when people
  1485. 56:29visit Craigslist they're probably
  1486. 56:30flipping through Reading Pages as
  1487. 56:32opposed to posting lots and lots and
  1488. 56:33lots of ads all at the same time so
  1489. 56:37there's some redundancy there that's
  1490. 56:38unfortunate
  1491. 56:39AEL
  1492. 56:41yeah just build upon that you
  1493. 56:45willing of code that you use on every
  1494. 56:48page again plus it's not a very elegant
  1495. 56:50solution to have a big folder on your on
  1496. 56:52your server containing 10,000 CLS okay
  1497. 56:54okay good so there's redundancy well
  1498. 56:56actually with all these thousands of
  1499. 56:58files there's redundancy too just in the
  1500. 56:59basic stuff like you have the same HTML
  1501. 57:01tag the same body tag the same link tag
  1502. 57:04the same script tag in every single page
  1503. 57:07if they're indeed just static HTML files
  1504. 57:09so whereas you get some benefits of
  1505. 57:11using something like PHP and recall our
  1506. 57:13MVC discussion where we factored out
  1507. 57:15template code like the header and the
  1508. 57:17footer so that we started it one place
  1509. 57:19and not thousands of places Craigslist
  1510. 57:21is kind of sacrificing that feature and
  1511. 57:24going with this instead so in the end
  1512. 57:26it's probably a calculated tradeoff you
  1513. 57:27get much better performance presumably
  1514. 57:30from just sving up the static content
  1515. 57:32but the price you pay is more disk space
  1516. 57:35but at the same time you know for a few
  1517. 57:36hundred dollars you can typically get
  1518. 57:37even bigger hard drives these days so
  1519. 57:39maybe that's actually the lesser of the
  1520. 57:41evils but there is one got there's
  1521. 57:43another big gotcha here if you've
  1522. 57:45generated tens of thousands of
  1523. 57:46Craigslist pages that look like this
  1524. 57:49what's the implication now and maybe why
  1525. 57:51are they stuck in the 90s well I decid
  1526. 57:54to add we change the background color
  1527. 57:57good change the design entirely which is
  1528. 57:59necessary I can't do that without
  1529. 58:01editing each one of those um 10,000
  1530. 58:04files and that's that could be done
  1531. 58:06automatically but it's much harder than
  1532. 58:08just uh editing a generic template that
  1533. 58:10generates it exactly if you want to
  1534. 58:12change the Aesthetics of the page and
  1535. 58:14add a background color change the CSS or
  1536. 58:16make it the font something other than
  1537. 58:17Times New Roman it's non-trivial now
  1538. 58:20because assuming this is a fully intact
  1539. 58:22HTML file with no server include
  1540. 58:25mechanism no like require mechanism like
  1541. 58:27you have in PHP you have to now change
  1542. 58:30the background color in tens of
  1543. 58:32thousands of files and less maybe you at
  1544. 58:34least put it in a CSS file but even then
  1545. 58:37if it's a less trivial change than color
  1546. 58:39suppose you want to restructure the HTML
  1547. 58:41of the page then you really have to do a
  1548. 58:42massive find and replace or more
  1549. 58:45realistically probably regenerate all
  1550. 58:4710,000 plus pages and I'm we latched on
  1551. 58:50to 10,000 arbitrarily but it's a lot of
  1552. 58:53pages in this case so upsides and
  1553. 58:56downsides they're one of the few people
  1554. 58:57on the internet who do this particular
  1555. 58:59approach um but it does have some value
  1556. 59:01and I think the last time I read up on
  1557. 59:03statistics they get by with relatively
  1558. 59:04little Hardware as a result which is
  1559. 59:06definitely compelling so myle query
  1560. 59:09cache this is a mechanism that we didn't
  1561. 59:10use but it's so easily enabled on a
  1562. 59:14typical server with mySQL there's a file
  1563. 59:16called my.cnf for your configuration
  1564. 59:19file and you can simply add a directive
  1565. 59:21like query cach type equals one and then
  1566. 59:24restart the server to enable the query
  1567. 59:26cache which pretty much does what it
  1568. 59:28says the ne if you execute a command
  1569. 59:30like select Fu from bar where baz equals
  1570. 59:33123 that will be could be slow the first
  1571. 59:36time you execute it if you don't have an
  1572. 59:38index or if you have a really huge table
  1573. 59:42but the next time you execute it if the
  1574. 59:44query cache is on and that row hasn't
  1575. 59:46changed the response is going to come
  1576. 59:47back much more quickly so MySQL provides
  1577. 59:50this kind of caching for identically
  1578. 59:52executed queries which might certainly
  1579. 59:54happen a lot if a user is navigating
  1580. 59:56your website going forward and back
  1581. 59:58quite a bit mcash is an even more
  1582. 1:00:01powerful U mechanism um Facebook has
  1583. 1:00:04made great use of this over the years
  1584. 1:00:06especially initially mcash is a memory
  1585. 1:00:08cache so it is a piece of software a
  1586. 1:00:11server that you run on a server it can
  1587. 1:00:12be on the same server as your web server
  1588. 1:00:15it can be on a different box altogether
  1589. 1:00:17but it essentially is a mechanism that
  1590. 1:00:19stores whatever you want in Ram and it
  1591. 1:00:23does this with in the PHP context with
  1592. 1:00:25code like this so this mcash can be used
  1593. 1:00:28by all sorts of languages here is php's
  1594. 1:00:31own interface to it and you use mcash as
  1595. 1:00:34follows you first connect to the mcash
  1596. 1:00:36server using mcash connect which is very
  1597. 1:00:38similar in spirit to mySQL connect which
  1598. 1:00:40you might recall from a few lectures
  1599. 1:00:42back then we try in this example to get
  1600. 1:00:45a user so the context here is it's
  1601. 1:00:47pretty expensive to do select star from
  1602. 1:00:49users on my database table because I've
  1603. 1:00:52got millions of users in this table and
  1604. 1:00:54I'd really rather not execute that query
  1605. 1:00:56more often than I have to I'd rather
  1606. 1:00:58execute it once save the results in Ram
  1607. 1:01:01and the next time I need that user go
  1608. 1:01:03into the ram go into cache to get that
  1609. 1:01:05user rather than touching the database
  1610. 1:01:07so there's this sort of tier of
  1611. 1:01:10performance objectives disc is slow
  1612. 1:01:12right spinning discs especially slow but
  1613. 1:01:15it's fast to serve up so generally you
  1614. 1:01:18might want to store something instead of
  1615. 1:01:19on disk you want to store it in a table
  1616. 1:01:21that has indexes so that you can search
  1617. 1:01:24it more quickly for instance think back
  1618. 1:01:26to project zero the XML file it's
  1619. 1:01:28relatively small but at the same time
  1620. 1:01:30anytime you wanted to search it you had
  1621. 1:01:31to load it from disc build up a Dom
  1622. 1:01:33thanks to the simple XML API then search
  1623. 1:01:36it kind of annoying it'd be nice if we
  1624. 1:01:38could skip the disk step so that things
  1625. 1:01:40would just be faster and thus was born
  1626. 1:01:42MySQL in Project one MySQL is a server
  1627. 1:01:45which means it's always running it's
  1628. 1:01:46using some Ram so in that case you have
  1629. 1:01:48the ability to execute queries on data
  1630. 1:01:51that's hopefully in Ram but even if it
  1631. 1:01:53isn't you at least have the opportunity
  1632. 1:01:54to Define indexes primary Keys unique
  1633. 1:01:57keys index Fields so that at least you
  1634. 1:01:59can search that data more readily than
  1635. 1:02:01you can with say XPath in XML so the
  1636. 1:02:04next step is not even to use a database
  1637. 1:02:06because database queries can be
  1638. 1:02:08expensive relative to just a cash which
  1639. 1:02:10is just a key value store I want to give
  1640. 1:02:13you x equals y and the next time I ask
  1641. 1:02:15for X you give me Y and I want it quick
  1642. 1:02:17much faster than a database would return
  1643. 1:02:19it so here we've gone and connected to
  1644. 1:02:21the memory cache demon the server in the
  1645. 1:02:23second line
  1646. 1:02:25I am trying to get something from the
  1647. 1:02:27cache the arguments to mem cach get take
  1648. 1:02:30the first argument is a uh a reference
  1649. 1:02:34to the cache that you want to grab
  1650. 1:02:35something from and then dollar sign ID
  1651. 1:02:38just represents something like one two3
  1652. 1:02:39the ID of the user that I want to get if
  1653. 1:02:42the user is null what's the implication
  1654. 1:02:45apparently Isaac well you do the quy all
  1655. 1:02:49over again okay good but in what case
  1656. 1:02:51would uh user be null do you think um
  1657. 1:02:54when they don't exist good when they're
  1658. 1:02:56not in the cache when user One Two Three
  1659. 1:02:58or whoever I'm looking for is not in the
  1660. 1:02:59cache that variable is going to be null
  1661. 1:03:01and so we do this if condition as Isaac
  1662. 1:03:03says and here there's some somewhat
  1663. 1:03:05familiar code PDO which relates to my
  1664. 1:03:07SQL in our case um we connect to the
  1665. 1:03:11database uh using that user and pass we
  1666. 1:03:13then execute the query function in PDO
  1667. 1:03:16in this case select star from users
  1668. 1:03:18where ID equals ID I'm not using my I'm
  1669. 1:03:21not um escaping ID because in this case
  1670. 1:03:24I'm assuming that I know it's an integer
  1671. 1:03:25so it's not a dangerous string just to
  1672. 1:03:27be clear then I'm calling fetch to get
  1673. 1:03:29back an associative array of my data the
  1674. 1:03:32user's name email address ID whatever
  1675. 1:03:35else I've got in my database but then
  1676. 1:03:37the last thing I do before apparently
  1677. 1:03:40nothing else because this is out of
  1678. 1:03:41context before actually using that user
  1679. 1:03:44for anything what am I doing with him
  1680. 1:03:46Axel you're storing it in the exactly
  1681. 1:03:50I'm storing a key value pair in the
  1682. 1:03:52cache whereby the key is the the user's
  1683. 1:03:54ID so this implies that there's an ID
  1684. 1:03:57field in the user object that came back
  1685. 1:03:59from the database from this line here
  1686. 1:04:01and the value is the user object itself
  1687. 1:04:04so again a memcache in this case is a
  1688. 1:04:06key value storage mechanism and the next
  1689. 1:04:09time I want to look up this user I want
  1690. 1:04:10to look him up by his ID and case in
  1691. 1:04:14point that's what I did in line two up
  1692. 1:04:16top now caches are finite because Ram is
  1693. 1:04:21finite and even disk is finite so what
  1694. 1:04:24could happen eventually with my
  1695. 1:04:26cash just by nature of that those
  1696. 1:04:29constraints Axel it gets so big can't on
  1697. 1:04:33Ma good So eventually the cash could get
  1698. 1:04:35so big you can't keep it on the machine
  1699. 1:04:36so what would be a reasonable thing to
  1700. 1:04:39do at that point when you've run out of
  1701. 1:04:41Ram or dis space for your
  1702. 1:04:46cash you're the person implementing
  1703. 1:04:48mcash itself now what do you do in that
  1704. 1:04:50case you could just kind of quit
  1705. 1:04:52unexpected error but that would kind of
  1706. 1:04:56be bad and completely
  1707. 1:05:00unnecessary what could you
  1708. 1:05:03do is it
  1709. 1:05:06sorry yeah so some kind of garbage
  1710. 1:05:08collection and what which things would
  1711. 1:05:10you collect what things would you uh
  1712. 1:05:12remove from
  1713. 1:05:18memory
  1714. 1:05:19good so we can essentially expire
  1715. 1:05:22objects based on when they were put in
  1716. 1:05:24so if I put in user 123 yesterday and I
  1717. 1:05:28haven't touched him since or needed him
  1718. 1:05:30since and I need more space well out
  1719. 1:05:32goes user 123 and I can reuse that space
  1720. 1:05:35that memory for user 456 if user 456 is
  1721. 1:05:39the next person I'm trying to insert
  1722. 1:05:41into the cache so indeed this is a very
  1723. 1:05:43common mechanism whereby the first one
  1724. 1:05:46in is the first one out if that object
  1725. 1:05:49has not been needed since by contrast if
  1726. 1:05:52123 is just one of these power users who
  1727. 1:05:54logging in quite a bit and he he he or
  1728. 1:05:56she is logging in again and again and
  1729. 1:05:58again well I should remember every time
  1730. 1:06:00and we don't see it in the code here but
  1731. 1:06:02every time I get a cach hit and I
  1732. 1:06:05actually find user 123 in the cache I
  1733. 1:06:08could somehow execute another mcash
  1734. 1:06:10function that just touches the user
  1735. 1:06:13object so to speak thereby updating his
  1736. 1:06:15timestamp to be this moment in time so
  1737. 1:06:17that you remember that he was just
  1738. 1:06:20selected and hopefully mcash get itself
  1739. 1:06:22would do that for us and indeed it does
  1740. 1:06:24I don't need to do this manually the
  1741. 1:06:25cache software would remember oh you
  1742. 1:06:28asked for user 1 two 3 I should move
  1743. 1:06:30probably move him back to the front of
  1744. 1:06:31the line so that the person at the end
  1745. 1:06:32of the line is the first one to get
  1746. 1:06:34evicted next time around so it's a
  1747. 1:06:37wonderfully useful mechanism and
  1748. 1:06:38Facebook is very read heavy or very
  1749. 1:06:40right
  1750. 1:06:42heavy if you're a
  1751. 1:06:47user it's kind of both these days you
  1752. 1:06:50know early on it was much more read
  1753. 1:06:52heavy than write heavy because there
  1754. 1:06:54were no like status updates and you
  1755. 1:06:56would just have your profile and that
  1756. 1:06:57was about it so these days there's
  1757. 1:06:59definitely more rights but I'm going to
  1758. 1:07:00guess that reads are still more common
  1759. 1:07:03than not right when you log if you're a
  1760. 1:07:04Facebook user and you log into your uh
  1761. 1:07:07account and you see your newsfeed you
  1762. 1:07:09know you might have 10 20 whatever
  1763. 1:07:10friends show up in that Newsfeed that's
  1764. 1:07:12potentially like 10 or 20 queries of
  1765. 1:07:15some sort and yet you're probably not
  1766. 1:07:17going to update your status 30 times at
  1767. 1:07:20in that same unit of time so odds are
  1768. 1:07:22Facebook is still a little more read
  1769. 1:07:24heavy which makes cashes all the more
  1770. 1:07:26compelling because if your own profile
  1771. 1:07:28isn't changing all that often at least
  1772. 1:07:31you might get 10 page views 100 page
  1773. 1:07:33views by friends or random strangers
  1774. 1:07:35before you actually update your status
  1775. 1:07:36or your profile again that's an
  1776. 1:07:38opportunity for optimization so early on
  1777. 1:07:40and this day Facebook uses things like
  1778. 1:07:42mcash quite a bit so that they're not
  1779. 1:07:44hitting their various databases just to
  1780. 1:07:46generate your profile they're instead
  1781. 1:07:48just getting the results of some
  1782. 1:07:50previous lookup unless it has since
  1783. 1:07:53expired
  1784. 1:07:55well on to mySQL optimization so that
  1785. 1:07:58you can squeeze all the more performance
  1786. 1:07:59out of your setup so this table is a
  1787. 1:08:01little more overwhelming right now than
  1788. 1:08:02it needs to be but recall our discussion
  1789. 1:08:04of MySQL storage engine some time ago
  1790. 1:08:07and we talked briefly about my Isam and
  1791. 1:08:09INB does anyone remember at least one of
  1792. 1:08:12the distinguishing characteristics of
  1793. 1:08:14those two storage engines and again a
  1794. 1:08:16storage engine was just like the
  1795. 1:08:17underlying format that was used to store
  1796. 1:08:20your database data um I think in
  1797. 1:08:24support transaction good so INB which is
  1798. 1:08:28the default these days so you haven't
  1799. 1:08:30really needed to think about this much
  1800. 1:08:32since project one um in ODB supports
  1801. 1:08:34transactions whereas my Isam does not my
  1802. 1:08:37Isam uses locks which are full table
  1803. 1:08:39locks but T does tend to have some other
  1804. 1:08:42properties and these this list here is a
  1805. 1:08:45very long list of the various
  1806. 1:08:47distinctions among these several storage
  1807. 1:08:49engines um transactions is one of them
  1808. 1:08:52um but there's a few other storage
  1809. 1:08:54engines here that I thought I would just
  1810. 1:08:55draw our attention to so
  1811. 1:08:59one you have a memory engine uh
  1812. 1:09:02otherwise known as a heap engine this is
  1813. 1:09:05a table that's intentionally only stored
  1814. 1:09:07in Ram which means if you lose power
  1815. 1:09:09server dies or whatnot the entire
  1816. 1:09:11contents of these memory tables will be
  1817. 1:09:13lost but still kind of a nice feature if
  1818. 1:09:16you yourself want to implement a cache
  1819. 1:09:18relatively easily by writing keys and
  1820. 1:09:21values into your database into two
  1821. 1:09:22columns Maybe you yourself can Implement
  1822. 1:09:25some kind of cash to avoid having to
  1823. 1:09:27touch maybe much larger tables that you
  1824. 1:09:29yourself have so that's an option to you
  1825. 1:09:32archive storage engine haven't had to
  1826. 1:09:34use this but take a guess as to what it
  1827. 1:09:37does besides archiving
  1828. 1:09:41something what does this engine do for
  1829. 1:09:43you do you
  1830. 1:09:52think
  1831. 1:09:56and what what was the last sentence the
  1832. 1:09:57last part of your
  1833. 1:10:02comments oh it doesn't store anything in
  1834. 1:10:04cash you have to query it all the time
  1835. 1:10:05not quite so the property you're
  1836. 1:10:07actually getting and you can kind of see
  1837. 1:10:10it here um but there's some footnotes on
  1838. 1:10:13the other storage engines is it's
  1839. 1:10:15compressed by default so archive tables
  1840. 1:10:18are actually slower to query but they're
  1841. 1:10:21automatically compressed for you so they
  1842. 1:10:23take up much much less space so a common
  1843. 1:10:25case uh common use case for archive
  1844. 1:10:28tables might be log files where you want
  1845. 1:10:31to keep the data around and you want to
  1846. 1:10:32write out a whole bunch of key of values
  1847. 1:10:35in a row every time someone hits your
  1848. 1:10:37web server anytime something buys
  1849. 1:10:39someone but suppose you rarely query
  1850. 1:10:41that data you're keeping it for
  1851. 1:10:42posterity for research purposes for
  1852. 1:10:44Diagnostic purposes but you're not going
  1853. 1:10:46to do any selects on it any time soon so
  1854. 1:10:48it would just be a waste to keep use
  1855. 1:10:50more dis space than you need to so
  1856. 1:10:52you're willing to sacrifice some future
  1857. 1:10:54performance when you do need to query it
  1858. 1:10:56for some long-term dis saving so the
  1859. 1:10:58archive format allows you to do that NDB
  1860. 1:11:01is a network uh storage engine which is
  1861. 1:11:03used for clustering so that actually
  1862. 1:11:05there is a way of addressing the issue
  1863. 1:11:08of single points of failure that we
  1864. 1:11:09discussed earlier with shared storage
  1865. 1:11:11but we'll see a simpler approach in just
  1866. 1:11:13a
  1867. 1:11:14moment so in the world of datab bases
  1868. 1:11:18like MySQL they typically offer this
  1869. 1:11:20replication feature that I mentioned
  1870. 1:11:22earlier so replication is all about
  1871. 1:11:24making automatic copies of something and
  1872. 1:11:26the terminology generally goes as
  1873. 1:11:27follows you generally have a master
  1874. 1:11:29database which is where you read data
  1875. 1:11:32from and write data to but just for good
  1876. 1:11:35measure that Master has one or more
  1877. 1:11:37slave databases attached to it via
  1878. 1:11:39network connection and their purpose in
  1879. 1:11:42life is to get a copy of every row
  1880. 1:11:45that's in the master database you can
  1881. 1:11:47think of it rather simply as anytime a
  1882. 1:11:49query is executed on the master that
  1883. 1:11:51same query is copied down to one or more
  1884. 1:11:53slaves and they do the exact same thing
  1885. 1:11:55so that in theory the master and all of
  1886. 1:11:58these slaves are identical to one
  1887. 1:11:59another so what's the upside now of
  1888. 1:12:02having databases one two three and four
  1889. 1:12:05all of which are copies of one another
  1890. 1:12:07apparently what problems does this solve
  1891. 1:12:09for us if
  1892. 1:12:11any AEL
  1893. 1:12:17datab good so if something if database
  1894. 1:12:19one dies because of human error you trip
  1895. 1:12:21over the court hard drive dies r Fizzles
  1896. 1:12:24out whatever the case may be you have
  1897. 1:12:26literally three backups that are
  1898. 1:12:28identical so there's no tapes involved
  1899. 1:12:30there's no backup server I mean these
  1900. 1:12:31are full-fledged databases and in the
  1901. 1:12:33simplest case you could just unplug the
  1902. 1:12:36master plug in the slave and voila you
  1903. 1:12:38now have a new master and you might have
  1904. 1:12:40to do a bit of reconfiguration in the
  1905. 1:12:42databases to make him to promote him to
  1906. 1:12:44master so to speak and then leave
  1907. 1:12:46servers three and four as the New Slaves
  1908. 1:12:48while you fix server number one but that
  1909. 1:12:51would be one approach here so so you
  1910. 1:12:53have some redundancy even though you
  1911. 1:12:54might have a little bit of downtime at
  1912. 1:12:56least you can get back up and running
  1913. 1:12:57quickly and indeed you could automate
  1914. 1:12:59this process if you notice that the
  1915. 1:13:00master is down you could uh take him
  1916. 1:13:02offline completely promote the slave and
  1917. 1:13:05reconfigure them all just by writing a
  1918. 1:13:07script what
  1919. 1:13:09else how else could we take advantage of
  1920. 1:13:11this
  1921. 1:13:20topology let me ask a more leading
  1922. 1:13:22question
  1923. 1:13:24in the context of Facebook especially
  1924. 1:13:26early days how might they in particular
  1925. 1:13:30have made good use of this
  1926. 1:13:36topology AEL well maybe if you get a lot
  1927. 1:13:40of a lot of queries uhhuh you can
  1928. 1:13:43Outsource them to different slaves okay
  1929. 1:13:45so if you're getting a lot of queries
  1930. 1:13:47you could you know maybe you could just
  1931. 1:13:48load balance across database servers and
  1932. 1:13:51absolutely you could the load balancers
  1933. 1:13:52don't have to be used for HTTP alone you
  1934. 1:13:54could use it for MySQL traffic but why
  1935. 1:13:56do I say Facebook in particular early on
  1936. 1:13:59they didn't get that many queries but
  1937. 1:14:01this was still a good Paradigm for
  1938. 1:14:04them why yeah why is this good
  1939. 1:14:15perhaps so back to my hypothesis that
  1940. 1:14:18they're more read heavy than write Heavy
  1941. 1:14:21How can you
  1942. 1:14:24adapt that that reality to this
  1943. 1:14:27particular topology effectively or put
  1944. 1:14:30another way why is this a good topology
  1945. 1:14:33for a website that is very read heavy
  1946. 1:14:35and less write heavy
  1947. 1:14:44Ben
  1948. 1:14:47okay okay good so reading can be
  1949. 1:14:49expedited so if we kind of combine Ben
  1950. 1:14:51and Axel's proposals here for a read
  1951. 1:14:53heavy website like Facebook certainly in
  1952. 1:14:55the early days you could just write your
  1953. 1:14:57code in such a way that any select
  1954. 1:14:58statements go to databases two three or
  1955. 1:15:02four and any inserts updates or deletes
  1956. 1:15:04have to go apparently to server one
  1957. 1:15:08which even though that query then has to
  1958. 1:15:10propagate to servers 2 three and four it
  1959. 1:15:12is less common and that happens
  1960. 1:15:14automatically so the code wise you don't
  1961. 1:15:16have to worry about it too much and if
  1962. 1:15:18you're suffering a bit of performance
  1963. 1:15:19there well you can just throw more
  1964. 1:15:20servers at it and have even more read
  1965. 1:15:22servers to lighten the load for further
  1966. 1:15:23so this approach of having slaves that
  1967. 1:15:26can typically be used either for
  1968. 1:15:27redundancy so you just have a hot spare
  1969. 1:15:30ready to go or so that you can balance
  1970. 1:15:33read requests across them is a very nice
  1971. 1:15:36solution but of course every time we
  1972. 1:15:39solve one problem we've introduced
  1973. 1:15:41another or at least we haven't fixed yet
  1974. 1:15:42another here what is a fa what is a
  1975. 1:15:45fault in this layout
  1976. 1:15:49still be
  1977. 1:15:52paranoid
  1978. 1:15:56kind of talked about it earlier but like
  1979. 1:15:58what if one dies right unless this is
  1980. 1:16:01there's got to be some blip on the radar
  1981. 1:16:04here because we have to like promote a
  1982. 1:16:06slave and right so you still have a
  1983. 1:16:08single point of failure here at least
  1984. 1:16:10for rights we could keep Facebook Alive
  1985. 1:16:12by letting people browse profiles and
  1986. 1:16:14read profiles but status updates for
  1987. 1:16:16instance could be offline for as long as
  1988. 1:16:18it takes us to promote a slave to a
  1989. 1:16:20Master feels like it'd be nicer or at
  1990. 1:16:22least our prob ility would be better of
  1991. 1:16:24up time if we instead had not just a
  1992. 1:16:26single Master but again let's just throw
  1993. 1:16:28Hardware at the problem so another
  1994. 1:16:30common Paradigm is actually to have a
  1995. 1:16:32master master set up whereby as the
  1996. 1:16:35labels imply and as the arrows suggest
  1997. 1:16:38this time you could write to either
  1998. 1:16:40server one or two and if you happen to
  1999. 1:16:42write to server one that query gets
  2000. 1:16:44replicated on server two and vice versa
  2001. 1:16:48so now you could keep it simple you
  2002. 1:16:50could always write to one but then the
  2003. 1:16:52quer Theory goes to uh number two
  2004. 1:16:55automatically or you could write to
  2005. 1:16:57either thereby load balancing across the
  2006. 1:16:58two and they'll propagate between each
  2007. 1:17:01other but in this case here if you've
  2008. 1:17:04laid out your network connections
  2009. 1:17:06properly either one or two can go down
  2010. 1:17:08and you still have a master that you
  2011. 1:17:10could read from and you could even
  2012. 1:17:11implement this in code recall very
  2013. 1:17:13simply we had the MySQL connect function
  2014. 1:17:15weeks ago or even the PDO Constructor
  2015. 1:17:18function which tries to connect to a
  2016. 1:17:19database you could implement this in PHP
  2017. 1:17:22code if MySQL connect fails when
  2018. 1:17:24connecting to server one then just try
  2019. 1:17:26server two so you yourself could build
  2020. 1:17:28in some redundancy so that now we could
  2021. 1:17:30lose server one or two and not have to
  2022. 1:17:32intervene as humans just yet because we
  2023. 1:17:34at least still have a second master that
  2024. 1:17:36we can continue writing to even though
  2025. 1:17:39server one is Now offline for some
  2026. 1:17:41amount of
  2027. 1:17:42time all right but we still have to
  2028. 1:17:44Route traffic there so in pursuit of
  2029. 1:17:47this idea of load balancing here's a
  2030. 1:17:49more complex picture that starts to
  2031. 1:17:51unite some of our web ideas and some of
  2032. 1:17:53our database ideas so at the top there
  2033. 1:17:55we have some kind of network we have a
  2034. 1:17:57load balancer in between and then we
  2035. 1:17:59have this frontend tier so web servers
  2036. 1:18:01are typically called a tier a service
  2037. 1:18:04tier um this is a multi-tiered
  2038. 1:18:06architecture would be the jargon here
  2039. 1:18:08and those web servers now apparently are
  2040. 1:18:10routing their requests through what in
  2041. 1:18:13order to reach some MySQL slaves for
  2042. 1:18:19reads who's the man in the middle here
  2043. 1:18:22yeah AEL uh for reads it would be the
  2044. 1:18:25load balancer okay so for reads yeah we
  2045. 1:18:28have a second load balancer depicted
  2046. 1:18:30here frankly in reality they could be
  2047. 1:18:32one and the same they could be the same
  2048. 1:18:33device but just listening for different
  2049. 1:18:35types of connections but for now they're
  2050. 1:18:37drawn more simply as separate now we
  2051. 1:18:39have one MySQL master so we also have
  2052. 1:18:41wires or arrows pointing from the web
  2053. 1:18:43servers to the master and the master
  2054. 1:18:45meanwhile has some kind of connection to
  2055. 1:18:47the slaves so not bad no frankly this is
  2056. 1:18:50starting to hurt my brain because now
  2057. 1:18:52what was a very very simple class where
  2058. 1:18:54you have a nice uh self-contained
  2059. 1:18:56Appliance on your machine on your laptop
  2060. 1:18:58does everything web database caching
  2061. 1:19:00anything you wanted to do my God look at
  2062. 1:19:02all the things we have to wire up now
  2063. 1:19:04and it's still not perfect what could
  2064. 1:19:05die here where what are our single
  2065. 1:19:07points of
  2066. 1:19:08failure Jack oh Isaac
  2067. 1:19:13sure my master okay so the MySQL Master
  2068. 1:19:16we haven't really solved that problem so
  2069. 1:19:18kind of be nice to steal part of the
  2070. 1:19:20previous picture and maybe uh it into
  2071. 1:19:23here
  2072. 1:19:25Jack same thing Exel load load balancers
  2073. 1:19:29right so single point of failure is very
  2074. 1:19:32well defined like single point of
  2075. 1:19:34failure just look for any um any
  2076. 1:19:37bottlenecks here whereby things point in
  2077. 1:19:40and then go out load balancers is one
  2078. 1:19:42here load balancers one there so it
  2079. 1:19:44turns out with load balancers for your
  2080. 1:19:46$100,000 you can get two of them
  2081. 1:19:48typically in the package and what they
  2082. 1:19:50tend to do is operate also in what's
  2083. 1:19:52called um similar in spirit to master
  2084. 1:19:55master mode but in the context of load
  2085. 1:19:56balancers it's typically called active
  2086. 1:19:58active as opposed to active passive and
  2087. 1:20:01the idea here is with active active you
  2088. 1:20:04have a pair of load balancers that are
  2089. 1:20:06constantly listening for connections
  2090. 1:20:08either one of which can receive uh
  2091. 1:20:11packets from the outside world and then
  2092. 1:20:13relay them to backend servers and what
  2093. 1:20:16they typically do is they send
  2094. 1:20:18heartbeats from left to right and right
  2095. 1:20:19to left so that if this guy ever stops
  2096. 1:20:22hearing a heartbeat from this guy so to
  2097. 1:20:24speak and a heartbeat is just like a
  2098. 1:20:25packet that gets sent every second or
  2099. 1:20:27something like that if this guy stops
  2100. 1:20:30hearing a heartbeat from this guy he
  2101. 1:20:31automatically assumes that this guy must
  2102. 1:20:33have gone offline so he's completely in
  2103. 1:20:35charge now and he continues to send
  2104. 1:20:38traffic uh from the outside world in or
  2105. 1:20:41if you instead have active passive mode
  2106. 1:20:43if this is the active guy at the moment
  2107. 1:20:46rather if this is the active guy at the
  2108. 1:20:47moment and he dies this guy similarly
  2109. 1:20:50detects oo no more heartbeat and what
  2110. 1:20:52the passive guy will do is promote
  2111. 1:20:53himself to active which essentially just
  2112. 1:20:55means he takes over the other guy's IP
  2113. 1:20:58address so that all traffic now comes to
  2114. 1:21:00him so in short we definitely need
  2115. 1:21:02another load balancer in the picture how
  2116. 1:21:04it's implemented is um is uh not as
  2117. 1:21:08important to us right now but having a
  2118. 1:21:10single load balancer is probably a bad
  2119. 1:21:12thing right and this is the tragedy you
  2120. 1:21:14can throw money at you can throw a lot
  2121. 1:21:16of brainpower at various tiers here but
  2122. 1:21:18if you have a lot of web servers a lot
  2123. 1:21:20of MySQL servers but you have one look
  2124. 1:21:22balancer just cuz it was really
  2125. 1:21:24expensive or you didn't know how to
  2126. 1:21:25configure it properly like the rest of
  2127. 1:21:27it is pretty much for not because you
  2128. 1:21:29still have things things that can die
  2129. 1:21:32and take down your entire website so
  2130. 1:21:35let's make this more complex still so
  2131. 1:21:37let's now introduce two load balancers
  2132. 1:21:40and let's actually introduce an idea of
  2133. 1:21:42partitioning and this was actually
  2134. 1:21:44something that Facebook coincidentally
  2135. 1:21:45did make good use of early on back in
  2136. 1:21:47the day there was harvard. harvard. thee
  2137. 1:21:50face.com there was mit. the facebook.com
  2138. 1:21:54and the earliest partitioning that they
  2139. 1:21:55used was to essentially have a different
  2140. 1:21:58server as best Outsiders could tell for
  2141. 1:22:00each school so they literally just like
  2142. 1:22:02copied the database copied the files
  2143. 1:22:04over to another server and then voila
  2144. 1:22:06thus was born MIT mit's copy of Facebook
  2145. 1:22:10but this is actually even though this
  2146. 1:22:12would get kind of messy for 800 million
  2147. 1:22:13users and thousands and thousands of
  2148. 1:22:15universities and uh networks it's pretty
  2149. 1:22:18clean early on because it's just
  2150. 1:22:21leverages this idea of part partitioning
  2151. 1:22:23right it's kind of we didn't have a
  2152. 1:22:24Facebook didn't have a big enough server
  2153. 1:22:26to handle Harvard and MIT so why not
  2154. 1:22:28just get two and say Harvard users go
  2155. 1:22:30here MIT users go here and now we've
  2156. 1:22:33kind of avoided that problem now
  2157. 1:22:35unfortunately when bu comes on we need a
  2158. 1:22:37third server but at least we can scale
  2159. 1:22:39horizontally now there is a catch with
  2160. 1:22:41partitioning as soon as you wanted to be
  2161. 1:22:43able to poke someone at MIT or vice
  2162. 1:22:45versa you had to somehow cross that
  2163. 1:22:47Harvard MIT boundary at which point it's
  2164. 1:22:50kind of a bad thing that they're all in
  2165. 1:22:51separate databases so early on there
  2166. 1:22:53were some features that you could only
  2167. 1:22:54do within your own network um not until
  2168. 1:22:57there was more shared State could you
  2169. 1:22:59send messages and the like so
  2170. 1:23:01partitioning though could be used even
  2171. 1:23:02more simply suppose that you just had a
  2172. 1:23:05whole bunch of users well you need to
  2173. 1:23:07scale your architecture horizontally why
  2174. 1:23:10don't I just put users whose last name
  2175. 1:23:11start with a to M on half of my servers
  2176. 1:23:14and then n through Z on the others right
  2177. 1:23:17and when they log in I just send them to
  2178. 1:23:18one or the other server based on that so
  2179. 1:23:20in general partitioning is not a bad
  2180. 1:23:23idea it's very common in databases
  2181. 1:23:26because you can still have redundancy a
  2182. 1:23:27whole bunch of slaves in this case here
  2183. 1:23:29whole bunch of slaves over here but you
  2184. 1:23:31can balance load based on some highlevel
  2185. 1:23:33user information not based on load not
  2186. 1:23:35round robin you can actually take into
  2187. 1:23:38account what someone's name is and then
  2188. 1:23:39send them to this particular server so
  2189. 1:23:42partitioning is a very common Paradigm
  2190. 1:23:45and then lastly just to slap a word on
  2191. 1:23:47It High availability refers to what we
  2192. 1:23:50described in the context of load
  2193. 1:23:51balancers but it can apply to databases
  2194. 1:23:53as well whereby High availability or ha
  2195. 1:23:56is the buzz word simply refers to some
  2196. 1:23:59kind of relationship between a pair or
  2197. 1:24:01more of servers that are somehow
  2198. 1:24:03checking each other's heartbeats so that
  2199. 1:24:05if one of them dies the other takes on
  2200. 1:24:07the entire burden of the uh of the
  2201. 1:24:10service that's being provided whether a
  2202. 1:24:12database or whether a load
  2203. 1:24:16balancer so even though we finally got
  2204. 1:24:19the iPad working it's a little small to
  2205. 1:24:20draw on so what I wanted to do
  2206. 1:24:23as our final example here is let me
  2207. 1:24:28raise the screen
  2208. 1:24:31here however one of these buttons will
  2209. 1:24:33do it
  2210. 1:24:37uh all right we're going to old school
  2211. 1:24:40now our first and last piece of chalk in
  2212. 1:24:42the
  2213. 1:24:43class
  2214. 1:24:44um let's
  2215. 1:24:49see uh start with the middle one
  2216. 1:24:52[Music]
  2217. 1:24:54all right let's build ourselves a
  2218. 1:24:55network here so we have a need for uh
  2219. 1:25:00one or more web servers one or more
  2220. 1:25:02databases maybe some load balancers but
  2221. 1:25:04we're also going to try to tie together
  2222. 1:25:06last week's conversation about security
  2223. 1:25:08so we'll have to think about firewalling
  2224. 1:25:09things out now so in very simple form we
  2225. 1:25:13have here a web server which I'll draw
  2226. 1:25:17is www all right so that's our web
  2227. 1:25:20server and now my website's doing so
  2228. 1:25:21well that I need a second web server so
  2229. 1:25:23I'm going to draw it like this and now
  2230. 1:25:26we need to revisit the issue of
  2231. 1:25:28balancing load so what felt like one of
  2232. 1:25:31our best options here how do I still
  2233. 1:25:35have the internet which I'll draw as a
  2234. 1:25:38cloud
  2235. 1:25:39here connected to both of these servers
  2236. 1:25:42somehow but I want the property of
  2237. 1:25:45sticky sessions so what are my options
  2238. 1:25:47or what was my best
  2239. 1:25:51option
  2240. 1:25:53how do I Implement sticky
  2241. 1:25:56sessions AEL use load balanc keep all
  2242. 1:26:00the sessions in one place okay good so
  2243. 1:26:02use a load balancer and store all the
  2244. 1:26:04sessions in one place and that's not
  2245. 1:26:07okay so we can actually do one but not
  2246. 1:26:09necessarily both of those let me
  2247. 1:26:11interpose now the thing we started
  2248. 1:26:13calling a black box so this is some kind
  2249. 1:26:15of load balancer now I still have my
  2250. 1:26:17backend servers and here's another one
  2251. 1:26:21here okay and now this is connected here
  2252. 1:26:24but I still want sticky sessions but you
  2253. 1:26:26know what shared states that sounded
  2254. 1:26:29expensive fiber channel ice scy sounded
  2255. 1:26:31complicated there's a simpler way how do
  2256. 1:26:33I ensure that I get sticky sessions
  2257. 1:26:34using only a load balancer and no shared
  2258. 1:26:37state
  2259. 1:26:44yet how can I ensure that when Alice
  2260. 1:26:47comes in and she's sent to This Server
  2261. 1:26:49the first time that the next time she
  2262. 1:26:51comes in she sent to the same
  2263. 1:26:59oneel okay good so why don't we have the
  2264. 1:27:02load balancer listen at the HTTP level
  2265. 1:27:05and when the response comes back from
  2266. 1:27:07the first web server let's give them
  2267. 1:27:09numbers so let's call this one and this
  2268. 1:27:11guy two the load balancer can insert
  2269. 1:27:13some kind of cookie that allows it to
  2270. 1:27:16remember that this user belongs on
  2271. 1:27:19server one and how it does that I don't
  2272. 1:27:20know it's a big random number and it's
  2273. 1:27:21got a table like um PHP does for its
  2274. 1:27:25sessions and figures out which server to
  2275. 1:27:27send her to in this case all right so
  2276. 1:27:29now I have a database the easiest way I
  2277. 1:27:31know how to set up a database is to put
  2278. 1:27:33it on the web server itself so much like
  2279. 1:27:35the cs50 appliance you have a database
  2280. 1:27:37in the same box as a web server if I now
  2281. 1:27:41have a database here and here on the
  2282. 1:27:43same boxes as our web servers what's the
  2283. 1:27:47most obvious problem that now
  2284. 1:27:50arises yeah Alice shopping cart is oh
  2285. 1:27:54well if she does something to her
  2286. 1:27:56profile or whatever it's just going to
  2287. 1:27:58be on server one and not on server two
  2288. 1:28:00since she just visited server one
  2289. 1:28:02exactly so if Alice just happens to end
  2290. 1:28:04up on server one and she updates her
  2291. 1:28:06profile or credit card information or
  2292. 1:28:07something persistent not the shopping
  2293. 1:28:09cart thing because that involves the
  2294. 1:28:10session but she does something
  2295. 1:28:11persistent it's going to persist on this
  2296. 1:28:13database and that's fine because sticky
  2297. 1:28:16sessions are solving all my problems now
  2298. 1:28:17but she comes back in a week or she logs
  2299. 1:28:20in from a different computer cookie
  2300. 1:28:22expires whatever and she ends up here
  2301. 1:28:24what happened to my credit card
  2302. 1:28:25information what happened to my profile
  2303. 1:28:27I now have no profile because I'm on a
  2304. 1:28:29different database so clearly this is
  2305. 1:28:31not going to fly unless we partition our
  2306. 1:28:35users and have the load balance or
  2307. 1:28:37actually take into account who is this
  2308. 1:28:39user and then send the user based on
  2309. 1:28:41Alice's last name always to the same
  2310. 1:28:43server so that could be one approach but
  2311. 1:28:45for now let's instead factor out the
  2312. 1:28:47database and say that it's not on the
  2313. 1:28:50web servers it's separate and it's it's
  2314. 1:28:52got some kind of internet connection
  2315. 1:28:53here of course we've solved one problem
  2316. 1:28:56but introduced a new one which is
  2317. 1:28:59what
  2318. 1:29:01ISAC single point of failure yeah so
  2319. 1:29:05single point of failure again so how can
  2320. 1:29:07we mitigate this well we can do a couple
  2321. 1:29:09of things we can attach slave databases
  2322. 1:29:12off of this and that's kind of nice but
  2323. 1:29:15it then involves somehow promoting a
  2324. 1:29:17slave to a Master in the event one dies
  2325. 1:29:19so maybe the cleanest approach would be
  2326. 1:29:21something like
  2327. 1:29:22two Master
  2328. 1:29:24databases so we'll call this DB1 this
  2329. 1:29:27will be db2 and now how do I want to do
  2330. 1:29:30this connect these like
  2331. 1:29:35this Isaac you shook your
  2332. 1:29:37head well you could connect the two
  2333. 1:29:40databases to each other okay so we
  2334. 1:29:42should probably do this for master
  2335. 1:29:44master replication so that's good but
  2336. 1:29:47what about these lines good
  2337. 1:29:50bad
  2338. 1:29:53answer's
  2339. 1:29:54bad why bad Jack well you can connect
  2340. 1:29:57each one to both of the right so the
  2341. 1:30:01problem we just identified was database
  2342. 1:30:03on same server as web server bad because
  2343. 1:30:05then it's talking only to it and if
  2344. 1:30:07Alice ends up on the other server she
  2345. 1:30:08has no data that you're expecting well
  2346. 1:30:10functionally this is equivalent I've
  2347. 1:30:12just drawn a line but they're still only
  2348. 1:30:13connected to each other and if the tri
  2349. 1:30:16traffic should probably not go like that
  2350. 1:30:18so we at least need to have some kind of
  2351. 1:30:19cross connect so okay so I can do
  2352. 1:30:23this but now what do I do so now my load
  2353. 1:30:27balancing has to be done in code if
  2354. 1:30:29those are the only uh components in my
  2355. 1:30:32system right now the line suggests that
  2356. 1:30:33dubdub du1 has a network connection to
  2357. 1:30:35DB1 and db2 but that means now I have to
  2358. 1:30:38do something like an if condition only
  2359. 1:30:40in my PHP code to say if this database
  2360. 1:30:42is up right here else if this database
  2361. 1:30:45is up right there and that's not bad but
  2362. 1:30:47now your developers have to know
  2363. 1:30:48something about the topology if you ever
  2364. 1:30:50introduce a third master or something
  2365. 1:30:52like that although my SQL wouldn't play
  2366. 1:30:54nicely with that now you have to change
  2367. 1:30:56your code this is not a nice layer of
  2368. 1:30:58abstraction so how else could we solve
  2369. 1:31:00this
  2370. 1:31:02Axel I don't like the idea of connecting
  2371. 1:31:04each of my web servers to the database
  2372. 1:31:07because frankly you know what this is
  2373. 1:31:08going to get really ugly if it starts
  2374. 1:31:10looking like this right very quickly
  2375. 1:31:13this degrades into a mess yeah get
  2376. 1:31:15another machine load Balan will okay
  2377. 1:31:18good all of that so connect your um
  2378. 1:31:22your dub du dub servers to below
  2379. 1:31:24balancer and then let it handle requests
  2380. 1:31:26and then you can Implement all kinds of
  2381. 1:31:28of features like say um they are both
  2382. 1:31:32Masters right they have the same data
  2383. 1:31:34but what if only users with u last name
  2384. 1:31:37that starts with end logs in well you're
  2385. 1:31:39going to have a load on one particular
  2386. 1:31:41server but then the load balancer can
  2387. 1:31:43take all those features we talked about
  2388. 1:31:44good CPU cycles and all that and
  2389. 1:31:47actually distribute uh my SQL queries
  2390. 1:31:49across databas okay good so we insert a
  2391. 1:31:52load balancer here which is connected to
  2392. 1:31:54both the dub machines and also the
  2393. 1:31:55database servers and then he can be
  2394. 1:31:58responsible for load balancing across
  2395. 1:31:59the two masters um it's actually harder
  2396. 1:32:02for the database to do any kind of
  2397. 1:32:03intelligence load balancing based on
  2398. 1:32:05last names at this point since the MySQL
  2399. 1:32:08traffic is going to operate with binary
  2400. 1:32:10messages not with HTTP style textual
  2401. 1:32:13messages um load balancer up here can
  2402. 1:32:15look at HTP headers and make Intelligent
  2403. 1:32:17Decisions it's harder and maybe not
  2404. 1:32:19impossible but it wouldn't be very
  2405. 1:32:20common to do load balancing based on
  2406. 1:32:23application layer intelligence here you
  2407. 1:32:25would probably push that to the PHP code
  2408. 1:32:27again in that case but this isn't bad
  2409. 1:32:30but Isaac doesn't like this picture now
  2410. 1:32:32because of what it still fails at one
  2411. 1:32:34point yeah so we still have the single
  2412. 1:32:36point of failure so you just cost me
  2413. 1:32:38even more money or more complexity even
  2414. 1:32:41if I'm using free software this just
  2415. 1:32:42takes more time now so now we have load
  2416. 1:32:45balancer one load balancer two I need to
  2417. 1:32:49do something like
  2418. 1:32:50this
  2419. 1:32:53um and even though this looks a little
  2420. 1:32:54ridiculous um oh actually it's a little
  2421. 1:32:56elegant that's pretty sexy so you would
  2422. 1:32:59do this with switches or some kind of
  2423. 1:33:01ethernet cables all going into some
  2424. 1:33:03Central source so suppose instead we
  2425. 1:33:06actually did that if you've ever plugged
  2426. 1:33:07in a computer into a network Jack which
  2427. 1:33:09most of you probably have even if you
  2428. 1:33:10have a laptop you don't connect these
  2429. 1:33:12computers all to themselves you instead
  2430. 1:33:14connect them to like a big switch that
  2431. 1:33:16has lots of ethernet ports that you can
  2432. 1:33:18plug into but now Isaac what what do you
  2433. 1:33:20not like about this idea if I'm plugging
  2434. 1:33:22everything into a
  2435. 1:33:24switch still fails yeah so welcome to
  2436. 1:33:27the world of like Network redundancy so
  2437. 1:33:30really the right way to do this is to
  2438. 1:33:32have two switches so almost every one of
  2439. 1:33:34your servers database and web alike as
  2440. 1:33:36well as your load balancers would
  2441. 1:33:38typically have at least two ethernet
  2442. 1:33:40Jacks in them and one cable would go to
  2443. 1:33:42one switch another cable would go to the
  2444. 1:33:43other switch you have to be super
  2445. 1:33:45careful not to create Loops of some sort
  2446. 1:33:47so switches have to be somewhat
  2447. 1:33:49intelligent typically so that you don't
  2448. 1:33:50create this crazy mess where traffic is
  2449. 1:33:52just bouncing and bouncing around in
  2450. 1:33:54your internal Network and nothing's
  2451. 1:33:55getting in or out so there's an uh
  2452. 1:33:58there's some care that has to be taken
  2453. 1:33:59but in general this is really the theme
  2454. 1:34:02in ensuring that you have not only
  2455. 1:34:03scalability but redundancy and higher
  2456. 1:34:06probabilities of uptime and resilience
  2457. 1:34:07against failure you really do start
  2458. 1:34:09cross-connecting many different things
  2459. 1:34:12but let's push harder Isaac what suppose
  2460. 1:34:14I fix the switch issue suppose I also
  2461. 1:34:16make this two load balancers and fix
  2462. 1:34:18that
  2463. 1:34:19issue what's something else could fail
  2464. 1:34:32now can't do this on an iPad very well
  2465. 1:34:35um so this is your data center here's
  2466. 1:34:38the door to your data
  2467. 1:34:39center Jack the building burns
  2468. 1:34:44down that's good more extreme than I had
  2469. 1:34:46in mind I was thinking the power goes
  2470. 1:34:47out but that works too um so the
  2471. 1:34:49building itself burns down or goes
  2472. 1:34:52offline you have some kind of network
  2473. 1:34:54disconnect between you and your ISP the
  2474. 1:34:55whole building or um the power indeed
  2475. 1:34:58does go out and this has happened in
  2476. 1:35:00fact one of the things that happens
  2477. 1:35:01every time Amazon goes out is the whole
  2478. 1:35:03world starts to think that clouds cloud
  2479. 1:35:06computing so to speak is a a bad thing
  2480. 1:35:09because oh my god look you can't keep
  2481. 1:35:10the cloud up but the tragedy here is in
  2482. 1:35:12this perception that cloud computing
  2483. 1:35:14really just refers to Outsourcing of
  2484. 1:35:16services and sharing resources like
  2485. 1:35:18power and networking and and security
  2486. 1:35:20and so forth across multiple customers
  2487. 1:35:23so Amazon Services ec2 elastic compute
  2488. 1:35:25cloud is kind of this picture here
  2489. 1:35:27whereby you don't own the servers but
  2490. 1:35:29you do rent space on them because they
  2491. 1:35:31give you vpss that happen to be housed
  2492. 1:35:33inside of this building Amazon offers
  2493. 1:35:35things called availability zones whereby
  2494. 1:35:37this might be an availability Zone
  2495. 1:35:38called us East one so this is a building
  2496. 1:35:40in Virginia in that particular case and
  2497. 1:35:43what they offer though is Us East 2 and
  2498. 1:35:45three and four they call them A and B
  2499. 1:35:47and C and D and what that simply means
  2500. 1:35:50in theory is that there's another
  2501. 1:35:52building like this drawn over there that
  2502. 1:35:54does not share the same power source
  2503. 1:35:56does not share the same networking
  2504. 1:35:58cables and so even if something goes
  2505. 1:36:00wrong in one building in theory the
  2506. 1:36:02other shouldn't be affected however
  2507. 1:36:04Amazon has suffered outages in multiple
  2508. 1:36:06availability zones multiple data centers
  2509. 1:36:09so in addition to having servers in
  2510. 1:36:10Virginia guess where else they have
  2511. 1:36:15servers anywhere else okay anywhere else
  2512. 1:36:17yeah that's actually a pretty hard
  2513. 1:36:18question the world's a big place so the
  2514. 1:36:20west coast and in Asia and in South
  2515. 1:36:22America and in Europe as well they have
  2516. 1:36:24different regions as they call them
  2517. 1:36:26inside of which are different data
  2518. 1:36:27centers or availability zones but this
  2519. 1:36:29just means that you can really drive
  2520. 1:36:31yourself crazy thinking through all the
  2521. 1:36:33possible failure scenarios because even
  2522. 1:36:34though Jack's building burning down is a
  2523. 1:36:37little extreme things like that do
  2524. 1:36:39happen right if you have a massive storm
  2525. 1:36:41like a tornado or hurricane that just
  2526. 1:36:43knocks out power absolutely could a
  2527. 1:36:45whole building goes down go down so what
  2528. 1:36:47do you do in that case well we have to
  2529. 1:36:49have a second data center availability
  2530. 1:36:51zone I'll draw it much smaller this time
  2531. 1:36:53even though it might be this physically
  2532. 1:36:54the same so here's another one suppose
  2533. 1:36:56that inside of this building is exactly
  2534. 1:36:58that same topology so now really what we
  2535. 1:37:01have is the internet outside these boxes
  2536. 1:37:04connecting to both buildings so so
  2537. 1:37:08internet is no longer inside the
  2538. 1:37:10building so once you have two data
  2539. 1:37:12centers how do you now distribute your
  2540. 1:37:15load across to Data Centers Axel well
  2541. 1:37:18then you can use the DNS trause yeah so
  2542. 1:37:21we we didn't really spend much time on
  2543. 1:37:23it but recall that you can do load
  2544. 1:37:24balancing at the DNS level and this is
  2545. 1:37:26indeed how you can do uh geography based
  2546. 1:37:29geoloc geography based load balancing
  2547. 1:37:32whereby now when someone on the internet
  2548. 1:37:34requests the IP address of something.com
  2549. 1:37:37they might get the IP address really of
  2550. 1:37:40this building or more specifically of
  2551. 1:37:41the load balancer in this building or
  2552. 1:37:44they might get the IP address of the
  2553. 1:37:45load balancer in this building right
  2554. 1:37:47when we did the NS lookup on Google we
  2555. 1:37:49got a whole bunch of results that's not
  2556. 1:37:51because they have one building with lots
  2557. 1:37:53of load balancers inside of it that's
  2558. 1:37:54because they probably have lots of
  2559. 1:37:56separate buildings or data centers
  2560. 1:37:58different countries even that themselves
  2561. 1:38:00have different entry points different IP
  2562. 1:38:02addresses so you have Global load
  2563. 1:38:05balancing as it's typically called then
  2564. 1:38:06the request comes into a building and
  2565. 1:38:08you still have the issue of somehow
  2566. 1:38:09making sure that subsequent traffic gets
  2567. 1:38:11to the same place because odds are
  2568. 1:38:13Google is not sharing your session
  2569. 1:38:14across entirely entirely different
  2570. 1:38:17continents even though they could be but
  2571. 1:38:19that would probably be expensive or slow
  2572. 1:38:21do so odds are you're going to stay in
  2573. 1:38:22that building for some amount of time
  2574. 1:38:24but again these ideas we've been talking
  2575. 1:38:26about just get magnified the bigger and
  2576. 1:38:28bigger you start to think and even then
  2577. 1:38:30you have potential downtime because if a
  2578. 1:38:32whole building goes offline and your
  2579. 1:38:34browser or your computer happens to have
  2580. 1:38:36cashed the IP address of that building
  2581. 1:38:40that data center could take some minutes
  2582. 1:38:42or some hours for your TTL to expire at
  2583. 1:38:46which point you get rerouted to
  2584. 1:38:48something else not too long ago just a
  2585. 1:38:50few weeks I think or was offline for
  2586. 1:38:52several hours one night cuz they use
  2587. 1:38:53Amazon um a bunch of other popular
  2588. 1:38:55websites too who use Amazon Services
  2589. 1:38:58were down alt together because they were
  2590. 1:39:00in a building or a set of buildings that
  2591. 1:39:02suffered this kind of downtime and it's
  2592. 1:39:05hard like if you are having the
  2593. 1:39:07fortunate problem of way too many users
  2594. 1:39:09and lots of Revenue um it gets harder
  2595. 1:39:11and harder to actually scale things out
  2596. 1:39:13globally so typically people do what
  2597. 1:39:15they can but as Isaac has gotten very
  2598. 1:39:16good at pointing out you can at least
  2599. 1:39:18avoid as best as possible these kinds of
  2600. 1:39:20single point points of
  2601. 1:39:23failure
  2602. 1:39:25questions so a word on security then
  2603. 1:39:27let's focus only on this picture not so
  2604. 1:39:29much on the buildings what kind of
  2605. 1:39:30traffic now needs to be allowed in and
  2606. 1:39:33out of the building so let me go ahead
  2607. 1:39:35and just give myself some internet here
  2608. 1:39:38connecting to the load balancer somehow
  2609. 1:39:41what type of internet traffic should be
  2610. 1:39:43coming from the outside world in if I'm
  2611. 1:39:46hosting a website with a lamp based
  2612. 1:39:48website yeah well you would want to fire
  2613. 1:39:51that allows only for 80 connections okay
  2614. 1:39:54good so I want TCP recall um which is
  2615. 1:39:57one of the transport protocols 80 on the
  2616. 1:40:00way in that's good but you just
  2617. 1:40:02compromised my ability to have certain
  2618. 1:40:05security why you're now blocking a very
  2619. 1:40:08useful type of traffic oh yeah ENC good
  2620. 1:40:10so we also want 443 which is the default
  2621. 1:40:14Port that's used for SSL for https based
  2622. 1:40:17URLs so that's good this means now that
  2623. 1:40:19the only traffic allowed into my data
  2624. 1:40:21center is TCP 80 and 443 now those
  2625. 1:40:24familiar with SSH you've also just
  2626. 1:40:26locked yourself out of your data center
  2627. 1:40:27because you cannot now SSH into your
  2628. 1:40:29data center so you might want to allow
  2629. 1:40:30something like Port 22 for SSH or you
  2630. 1:40:34might want to have an ssl-based VPN so
  2631. 1:40:36that you can connect somehow to your
  2632. 1:40:37data center remotely and again it
  2633. 1:40:39doesn't have to be a data center this
  2634. 1:40:40can just be some web hosting comp or
  2635. 1:40:42some VPS hosting company that you're
  2636. 1:40:44using and okay so we might need one or
  2637. 1:40:47more other ports for our VPN but for now
  2638. 1:40:48that's pretty good how about the load
  2639. 1:40:50balance bancers what kind of traffic
  2640. 1:40:52needs to go from the load balancer to my
  2641. 1:40:54web
  2642. 1:41:00servers Axel well it's really a mess to
  2643. 1:41:03keep it encrypted because once it's
  2644. 1:41:05inside the data center nobody else is
  2645. 1:41:07going to listen than the people inside
  2646. 1:41:09the so you would want to drop the
  2647. 1:41:11encryption and do 80 good and that's
  2648. 1:41:14actually very common to offload your SSL
  2649. 1:41:17to the load balancer or some special
  2650. 1:41:19device and then keep everything anything
  2651. 1:41:21else unencrypted because if you control
  2652. 1:41:23this it's at least safer not 100%
  2653. 1:41:25because if someone compromises this now
  2654. 1:41:27they're going to see your traffic
  2655. 1:41:28unencrypted but if you're okay with that
  2656. 1:41:30doing the SSL termination here so
  2657. 1:41:33everything's encrypted from the internet
  2658. 1:41:34down to here but then everything else
  2659. 1:41:36goes over normal unencrypted HTTP the
  2660. 1:41:39upside of that is remember the whole
  2661. 1:41:41certificate thing you don't need to put
  2662. 1:41:42your SSL certificate on all of your web
  2663. 1:41:44servers you can just put it in the load
  2664. 1:41:46balancer or the load balancers you can
  2665. 1:41:48get expensive load balancers to handle
  2666. 1:41:50the cryptog graphy and the the
  2667. 1:41:51computational cost thereof and you can
  2668. 1:41:53get cheaper web servers because they
  2669. 1:41:54don't need to worry as much about that
  2670. 1:41:56kind of overhead so that's one option so
  2671. 1:41:58CCP 80 here and here how about the
  2672. 1:42:00traffic between the web server and the
  2673. 1:42:03databases perhaps through these load
  2674. 1:42:07balancers this is a more of a trivia
  2675. 1:42:10question but what kind of what kind of
  2676. 1:42:12traffic is it even if you don't know the
  2677. 1:42:13port number
  2678. 1:42:15yeah it's
  2679. 1:42:18query yeah uh query ex or more specific
  2680. 1:42:20it's the SQL queries like select and
  2681. 1:42:22insert and delete and so forth so this
  2682. 1:42:26is generally TCP
  2683. 1:42:29336 which is the port number that my SQL
  2684. 1:42:33uses by default so what does this mean
  2685. 1:42:35um if you do have firewalling
  2686. 1:42:37capabilities and we haven't drawn any
  2687. 1:42:39firewalls per se so we do need to insert
  2688. 1:42:41some Hardware into this picture that
  2689. 1:42:43would allow us to actually make these
  2690. 1:42:45kinds of configuration changes but if we
  2691. 1:42:47assume we have that ability in large
  2692. 1:42:48part because all of these things are
  2693. 1:42:50plugged in in as we said to some kind of
  2694. 1:42:51switch well the switch could be a
  2695. 1:42:53firewall itself and we could make these
  2696. 1:42:55configuration changes we can further
  2697. 1:42:57lock things down why I mean everything
  2698. 1:43:00just works if I don't firewall
  2699. 1:43:02things why would I want to bother
  2700. 1:43:05tightening things so that only 8 and 443
  2701. 1:43:07are allowed here and 3306 is allowed
  2702. 1:43:10here and in fact notice there's no line
  2703. 1:43:12between these
  2704. 1:43:14guys well it would be really stupid to
  2705. 1:43:17keep for example 3306 open in the
  2706. 1:43:20because then people they might not be
  2707. 1:43:22able to because of other security
  2708. 1:43:24measures but in theory they they are
  2709. 1:43:26allowed by the firewall to quer your
  2710. 1:43:29database and do
  2711. 1:43:30SQL commands good exactly there's just
  2712. 1:43:33no need for people to be able to
  2713. 1:43:35potentially even execute SQL querries
  2714. 1:43:37coming in or make MySQL connections and
  2715. 1:43:39even if you're not even listening for
  2716. 1:43:40MySQL connections it again is sort of
  2717. 1:43:42the principle of the thing you should
  2718. 1:43:44really have the uh the principle of
  2719. 1:43:47least privilege whereby you only open
  2720. 1:43:49those doors that that people actually
  2721. 1:43:51have to go through otherwise you're just
  2722. 1:43:53inviting unexpected Behavior because you
  2723. 1:43:56left the door a jar so to speak you left
  2724. 1:43:57the port open and it's not clear whether
  2725. 1:44:00someone might in fact take advantage of
  2726. 1:44:02that case in point if somehow you screw
  2727. 1:44:04up or Apache screws up or PHP screws up
  2728. 1:44:06and this server is compromised it'd be
  2729. 1:44:09kind of nice if the only thing this
  2730. 1:44:11server can do is talk via MySQL to this
  2731. 1:44:14server and cannot for instance suddenly
  2732. 1:44:16SSH to this server or poke around or
  2733. 1:44:19execute any commands on your Network
  2734. 1:44:21other than MySQL so at least if the bad
  2735. 1:44:24guy takes this machine over he really
  2736. 1:44:25can't leave this uh rectangle here that
  2737. 1:44:30I've drawn so again beyond the scope of
  2738. 1:44:32things we've done in the class and even
  2739. 1:44:34though the appliance itself actually
  2740. 1:44:36does have a firewall that allows certain
  2741. 1:44:37ports in and out um all of the ones you
  2742. 1:44:40need we haven't had to fine-tune it um
  2743. 1:44:42for any of the projects realize that you
  2744. 1:44:44that even on something like a Linux
  2745. 1:44:46based operating system so in short as
  2746. 1:44:48soon as you have the happy problem of
  2747. 1:44:50having way too many users for your own
  2748. 1:44:52good lots of new problems arise even
  2749. 1:44:54though thus far we focused pretty much
  2750. 1:44:56entirely on the software side of things
  2751. 1:44:58so that is it for computer science s75
  2752. 1:45:01I'll Stick Around for questions
  2753. 1:45:02oneon-one um we still have a final
  2754. 1:45:04section tonight um for those of you who
  2755. 1:45:06would like to dive into some related
  2756. 1:45:08topics um otherwise realize that the
  2757. 1:45:10final project two um is its deadline is
  2758. 1:45:14coming up you should have gotten
  2759. 1:45:15feedback by from your TFS about project
  2760. 1:45:17one if not just drop him or her a note
  2761. 1:45:19um or me otherwise it's been a pleasure
  2762. 1:45:21having one in the class we will see you
  2763. 1:45:23online after tonight oh that's
  2764. 1:45:28okay thanks I wasn't trying to build up
  2765. 1:45:31to that there
  2766. 1:45:38so

About this transcript

This page contains the full transcript of CS75 (Summer 2012) Lecture 9 Scalability Harvard Web Development David Malan by archn, generated from the public captions YouTube serves with the video. The transcript has 19,464 words across 2,766 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 choose a caption track available on the video.

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, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.