WEBVTT

00:00:00.800 --> 00:00:08.032
<v Andrew>Okay, quick question. Everybody knows the error that says page not found. Four oh four. Where does that number come from?

00:00:08.082 --> 00:00:17.953
<v Ava>Oh, I know this one. Room four oh four, at CERN, the physics lab in Switzerland where the web was born. The first web server was in a room with that number.

00:00:18.003 --> 00:00:23.486
<v Ava>And Tim Berners-Lee had his desk there, and nobody could ever find him. Page not found.

00:00:23.536 --> 00:00:26.684
<v Andrew>That is the single most popular answer on the internet.

00:00:26.734 --> 00:00:28.634
<v Ava>Because it's a great story!

00:00:28.684 --> 00:00:32.542
<v Andrew>It's a great story. It's also a myth.

00:00:32.592 --> 00:00:34.348
<v Ava>What? No!

00:00:34.398 --> 00:00:45.196
<v Andrew>A man who worked right beside Berners-Lee at CERN says the number was never linked to any room or any place. And the real explanation is, honestly, funnier. We'll get there. I promise.

00:00:45.246 --> 00:00:48.146
<v Ava>You are ruining my entire childhood.

00:00:48.196 --> 00:00:50.336
<v Andrew>Your childhood contained a lot of room four oh four?

00:00:50.386 --> 00:00:52.825
<v Ava>It contained a lot of trivia.

00:00:58.910 --> 00:01:02.057
<v Andrew>Welcome to SimpleFlock Unpacked. I'm Andrew.

00:01:02.107 --> 00:01:06.142
<v Ava>And I'm Ava. This is episode two, How the Web Works.

00:01:06.192 --> 00:01:11.360
<v Andrew>Last time, we met one small website for a small group, and we saw that every website does four jobs.

00:01:11.410 --> 00:01:18.612
<v Andrew>The front end shows you things, the back end decides who can do what, the database stores everything, and hosting keeps it all switched on.

00:01:18.662 --> 00:01:22.102
<v Ava>And the waiter carrying messages between the dining room and the kitchen.

00:01:22.152 --> 00:01:28.912
<v Andrew>The waiter. Today, we follow the waiter. What exactly is in those messages, and how does the whole thing get started in the first place?

00:01:28.962 --> 00:01:33.586
<v Ava>So, what happens between pressing enter on an address, and a page showing up?

00:01:33.636 --> 00:01:35.988
<v Andrew>A lot, in about a tenth of a second.

00:01:37.360 --> 00:01:40.226
<v Andrew>Let's begin with two words. Client, and server.

00:01:40.276 --> 00:01:44.779
<v Ava>Okay. Those sound like a law firm.

00:01:44.829 --> 00:01:51.976
<v Andrew>They are much simpler. A client is whoever asks for things. A server is whoever answers. Your browser is a client.

00:01:52.026 --> 00:01:59.489
<v Andrew>And a server is just a computer, usually sitting in a data center somewhere, running a program that waits for requests.

00:01:59.539 --> 00:02:05.006
<v Ava>So a server isn't some special magic machine. It's a computer that's patiently waiting.

00:02:05.056 --> 00:02:12.562
<v Andrew>Patiently waiting, around the clock. And back to the restaurant, the client is the diner and the server is the kitchen.

00:02:12.612 --> 00:02:17.328
<v Ava>Okay. So I type the address of a website. Say, simpleflock dot com. What happens?

00:02:17.378 --> 00:02:26.073
<v Andrew>Three things. First, your browser needs to turn that name into a numeric address. Second, it opens a connection to that address.

00:02:26.123 --> 00:02:31.743
<v Andrew>Third, it sends a message that says, roughly, please give me the page at this path.

00:02:31.793 --> 00:02:35.242
<v Ava>Wait. Step one. Doesn't my browser just know where every website lives?

00:02:35.292 --> 00:02:46.117
<v Andrew>That's a very reasonable guess. And no, it would be impossible. Your browser asks a directory. It's called D N S, the domain name system.

00:02:46.167 --> 00:02:47.980
<v Ava>A phone book.

00:02:48.030 --> 00:02:52.056
<v Andrew>A phone book for the internet. You give it a name, it gives you back a number.

00:02:53.410 --> 00:03:00.710
<v Andrew>And the story behind it is great. Back in the early days of the network that came before the internet, there was no D N S.

00:03:00.760 --> 00:03:10.650
<v Andrew>There was a single text file, called HOSTS dot TXT, kept at Stanford Research Institute. It listed the name and the numeric address of every computer on the network.

00:03:10.700 --> 00:03:12.022
<v Ava>One file? For every computer?

00:03:12.072 --> 00:03:20.052
<v Andrew>One file, kept by one office in California. If you wanted to know who was out there, that was the place to look.

00:03:20.102 --> 00:03:22.604
<v Ava>That sounds like it could go badly.

00:03:22.654 --> 00:03:26.970
<v Andrew>It did. As the network grew, the file got too big and too slow to keep up.

00:03:27.020 --> 00:03:37.000
<v Andrew>So in nineteen eighty three, a computer scientist named Paul Mockapetris, working at the University of Southern California, designed the domain name system to replace it.

00:03:37.050 --> 00:03:42.043
<v Ava>So the phone book got replaced by a phone book that's spread out everywhere.

00:03:42.093 --> 00:03:46.840
<v Andrew>Exactly. No single office in charge of every name. And that's still how it works today.

00:03:48.180 --> 00:03:55.632
<v Ava>Okay, so my browser has the number. It opens a connection. And then it sends this message you mentioned.

00:03:55.682 --> 00:04:01.615
<v Andrew>And that message has a name. H T T P. It's the agreed format for those messages. Think of it as the waiter's order pad.

00:04:01.665 --> 00:04:04.284
<v Ava>Ah. So the order pad has a format.

00:04:04.334 --> 00:04:15.551
<v Andrew>A request has four parts. A method, which is what you want to do. A path, which is what you want to do it to. Optional headers, which are extra facts about you and the request.

00:04:15.601 --> 00:04:18.815
<v Andrew>And sometimes a body, which is data you're sending.

00:04:18.865 --> 00:04:20.592
<v Ava>And the method is what? Like, verbs?

00:04:20.642 --> 00:04:28.985
<v Andrew>Exactly verbs. There are four to know. Get means read something. It changes nothing. On SimpleFlock, that's loading the bulletin.

00:04:29.035 --> 00:04:31.245
<v Ava>Like asking to see the menu.

00:04:31.295 --> 00:04:41.054
<v Andrew>Right. Post means create something or perform an action. Signing in, or adding an event. Put means replace or update something, like saving the settings.

00:04:41.104 --> 00:04:45.029
<v Andrew>And delete removes something, like taking a song off the list.

00:04:45.079 --> 00:04:48.241
<v Ava>Read, create, update, remove. Okay.

00:04:48.291 --> 00:04:54.139
<v Andrew>And then the response comes back, with a status code, headers, and a body. And the status code is where this gets fun.

00:04:54.189 --> 00:04:57.153
<v Ava>Wait, is this where you tell me about my room?

00:04:57.203 --> 00:05:02.456
<v Andrew>It is. First, the basics. Two hundred means it worked.

00:05:02.506 --> 00:05:04.099
<v Ava>Good.

00:05:04.149 --> 00:05:09.098
<v Andrew>Four hundred means your request was malformed. The waiter couldn't read your handwriting.

00:05:09.790 --> 00:05:10.563
<v Ava>Ha.

00:05:10.613 --> 00:05:18.159
<v Andrew>Four oh one means you're not signed in. And four oh three is a subtle one. It means you are signed in, but you're not allowed to do that.

00:05:18.209 --> 00:05:19.364
<v Ava>What's an example?

00:05:19.414 --> 00:05:28.446
<v Andrew>On SimpleFlock, say a regular member tries to do an admin action. The server knows exactly who they are. It says, I know you, and no. That's a four oh three.

00:05:28.496 --> 00:05:33.182
<v Ava>So four oh one is I don't know who you are, and four oh three is I know exactly who you are.

00:05:33.232 --> 00:05:41.533
<v Andrew>Exactly. Then four oh four, nothing lives at that address. Four oh nine is a conflict, either the data changed under you, or the thing already exists.

00:05:41.583 --> 00:05:44.762
<v Andrew>Say two people tap the same empty role at the same moment.

00:05:44.812 --> 00:05:46.623
<v Ava>One of them is going to be disappointed.

00:05:46.673 --> 00:05:51.769
<v Andrew>One of them gets a four oh nine. And last, four twenty nine. Too many requests. Slow down.

00:05:53.343 --> 00:05:56.845
<v Andrew>Okay. Back to your room. Here's what actually happened.

00:05:56.895 --> 00:06:06.274
<v Andrew>A man named Robert Cailliau, who worked with Tim Berners-Lee at CERN, told Wired magazine in twenty seventeen that it was, quote, a complete myth.

00:06:06.324 --> 00:06:07.870
<v Ava>Ouch.

00:06:07.920 --> 00:06:17.046
<v Andrew>The explanation is much less romantic. Cailliau said that back then, computers had very little memory, so there was no room for long error messages.

00:06:17.096 --> 00:06:28.454
<v Andrew>Instead, the people building the web grouped the codes into ranges. Anything that starts with a two is success. A three means go somewhere else. A four means the client made a mistake.

00:06:28.504 --> 00:06:30.190
<v Andrew>A five means the server did.

00:06:30.240 --> 00:06:33.544
<v Ava>So the four in four oh four means...

00:06:33.594 --> 00:06:39.682
<v Andrew>That you made the mistake. You, personally. You asked for something that isn't there. And the zero four?

00:06:39.732 --> 00:06:46.293
<v Andrew>Cailliau said the numbers inside each range were picked, in his words, according to the whims of the programmer.

00:06:46.343 --> 00:06:50.377
<v Ava>So it's not a clue. It's just whatever number came next.

00:06:50.427 --> 00:06:56.190
<v Andrew>Pretty much. No room. No Tim Berners-Lee hiding at his desk.

00:06:56.240 --> 00:06:57.795
<v Ava>I'm going to have to grieve this one.

00:06:57.845 --> 00:07:06.394
<v Andrew>Take your time. And while we're being honest about error codes, there's one more I love. Four eighteen.

00:07:06.444 --> 00:07:09.025
<v Ava>I don't know that one. What does it say?

00:07:09.075 --> 00:07:10.139
<v Andrew>It says, I'm a teapot.

00:07:10.189 --> 00:07:11.895
<v Ava>I'm sorry, what? Is that a real one?

00:07:11.945 --> 00:07:25.021
<v Andrew>It is an official, written-down code. In nineteen ninety eight, on April first, an engineer named Larry Masinter published a document describing a protocol for controlling coffee pots over the web.

00:07:25.071 --> 00:07:34.683
<v Andrew>It was a joke. An April Fools' document. And in it, he defined the error you get if you ask a teapot to brew coffee. Four eighteen, I'm a teapot.

00:07:34.733 --> 00:07:39.948
<v Ava>Of course. And I assume the document said how the teapot should answer?

00:07:40.450 --> 00:07:43.636
<v Andrew>It said the reply may be short and stout.

00:07:43.686 --> 00:07:45.162
<v Ava>That is brilliant.

00:07:46.580 --> 00:07:53.682
<v Ava>Okay. I want to go back to something. You said the waiter carries these messages. But what if someone is listening in?

00:07:53.732 --> 00:08:03.947
<v Andrew>That's what H T T P S is for. It's H T T P wrapped in encryption, so that anyone listening on the cafe wifi sees only scrambled bytes. It's the padlock in the address bar.

00:08:03.997 --> 00:08:08.646
<v Ava>And the data inside the message. What does it look like?

00:08:08.696 --> 00:08:15.350
<v Andrew>Usually something called J S O N. It's a plain text format for handing structured data from one program to another.

00:08:15.400 --> 00:08:26.894
<v Andrew>For example, a bulletin item might travel as a title, Potluck, and a date in November. Both the browser and the server can read and write it easily, which is why almost every modern web app uses it.

00:08:26.944 --> 00:08:29.544
<v Ava>So J S O N is the language of the waiter's order pad.

00:08:29.594 --> 00:08:34.648
<v Andrew>Perfect. And one more thing. Remember the wristband from last time?

00:08:34.698 --> 00:08:38.745
<v Ava>The cookie.

00:08:38.795 --> 00:08:44.158
<v Andrew>The cookie. This is exactly why it exists. H T T P has no memory. Every request arrives like a stranger.

00:08:44.208 --> 00:08:53.629
<v Andrew>So after you sign in, the server hands your browser a small piece of text, and the browser sends it back automatically with every later request. That's how the server knows it's you.

00:08:53.679 --> 00:08:57.632
<v Ava>And we'll find out how it's made hard to fake.

00:08:57.682 --> 00:08:58.865
<v Andrew>In the security episode.

00:09:00.488 --> 00:09:06.451
<v Andrew>Now, the big design choice. How does SimpleFlock actually show you pages?

00:09:06.501 --> 00:09:09.238
<v Ava>Don't I just get a page? Like, click, new page?

00:09:09.288 --> 00:09:22.243
<v Andrew>That's the old way. In the old way, every click made the server build a fresh page of H T M L and send the whole thing back. SimpleFlock uses the newer pattern, called a single-page application.

00:09:22.293 --> 00:09:22.846
<v Andrew>An S P A.

00:09:22.896 --> 00:09:24.292
<v Ava>Single page. As in, there's only one?

00:09:24.342 --> 00:09:35.344
<v Andrew>In a sense. The server sends one bundle of JavaScript, one time. From then on, that JavaScript draws every screen itself, and only talks to the server to fetch or save data, in J S O N.

00:09:35.394 --> 00:09:40.537
<v Ava>So switching from the Bulletin tab to the Roles tab...

00:09:40.587 --> 00:09:53.422
<v Andrew>Feels instant, because no new page loads. The app just draws a different screen. In our restaurant, it's like the dining room redecorating itself, while the kitchen only sends over ingredients.

00:09:53.472 --> 00:09:56.431
<v Ava>And where does that conversation with the kitchen happen?

00:09:56.481 --> 00:10:05.391
<v Andrew>Everything that starts with slash A P I. Every route the server answers lives there. Anything else is a static file, the app itself.

00:10:05.441 --> 00:10:09.525
<v Ava>Okay, but how does that compare with the other ways to build it?

00:10:09.575 --> 00:10:20.567
<v Andrew>Let's go through them. The S P A is great for screens that feel instant and work like a real app. The front end and back end are cleanly separated, so either can change.

00:10:20.617 --> 00:10:33.700
<v Andrew>And it fits on a phone's home screen. The downsides, a large JavaScript download on the first visit, search engines and link previews see less, and you have to build your own loading and error screens.

00:10:33.750 --> 00:10:35.287
<v Ava>And the old way?

00:10:35.337 --> 00:10:44.256
<v Andrew>Server-rendered pages, like Rails, Django, P H P, or Laravel. The mental model is simple, the first view is fast, and it's great for content sites.

00:10:44.306 --> 00:10:51.274
<v Andrew>But every click is a round trip to the server, unless you add scripts, and it's harder to make it feel like an app.

00:10:51.324 --> 00:10:52.794
<v Ava>And there's something in between?

00:10:53.515 --> 00:11:01.058
<v Andrew>Two things. Server-rendered React, like Next dot J S or Remix. Fast first view, and app-like afterwards, all in one framework.

00:11:01.108 --> 00:11:10.881
<v Andrew>But more machinery, more concepts, and often tied to a framework and its hosting. And then there's an approach called HTML over the wire, like H T M X and Hotwire.

00:11:10.931 --> 00:11:22.391
<v Andrew>Very little JavaScript, and the server stays in charge. But it's less suited to rich interactions, like dragging to reorder a list, caching things offline, or heavy encryption in the browser.

00:11:22.441 --> 00:11:25.620
<v Ava>So why did SimpleFlock go with the S P A?

00:11:25.670 --> 00:11:36.127
<v Andrew>Two reasons. First, the front page is public and could have been server-rendered, but everything else is private, so search engines never see it, and the S P A's drawbacks mostly disappear.

00:11:36.177 --> 00:11:43.522
<v Andrew>Second, remember the private pillar? The encryption happens in your browser. That's much more natural when the browser does the work.

00:11:43.572 --> 00:11:45.936
<v Ava>So the choice follows the pillars.

00:11:45.986 --> 00:11:46.637
<v Andrew>It always does.

00:11:48.070 --> 00:11:54.850
<v Andrew>So here's what to take with you. The web is a conversation. A client asks, a server answers, and D N S finds the address.

00:11:54.900 --> 00:12:05.461
<v Andrew>The messages follow H T T P, with a verb on the way in and a status code on the way back. H T T P S keeps them private, J S O N carries the data, and cookies give a forgetful web a memory.

00:12:05.511 --> 00:12:14.522
<v Ava>And the number to remember is the first digit. Two means good. Four means you made the mistake. Five means the server did.

00:12:14.572 --> 00:12:17.082
<v Andrew>And never trust a good story about the number four oh four.

00:12:17.132 --> 00:12:21.801
<v Ava>I'll miss my room.

00:12:21.851 --> 00:12:29.543
<v Andrew>Next time, episode three, The Languages. A browser speaks only three, and this site uses four, each with one narrow job.

00:12:29.593 --> 00:12:35.091
<v Andrew>We'll find out why one of them is the real secret to how one person can run all of it.

00:12:35.141 --> 00:12:36.084
<v Ava>I'm Ava.

00:12:36.134 --> 00:12:39.313
<v Andrew>And I'm Andrew. Thanks for listening to SimpleFlock Unpacked.

00:12:39.363 --> 00:12:46.165
<v Ava>Music by Kevin MacLeod, at incompetech dot com, used under a Creative Commons Attribution four point oh license.
